
import unittest

from openstack.telemetry.v2 import sample
from openstack.tests.functional import base


@unittest.skipUnless(base.service_exists(service_type="metering"),
                     "Metering service does not exist")
class TestSample(base.BaseFunctionalTest):

    def test_list(self):
        for meter in self.conn.telemetry.meters():
            sot = next(self.conn.telemetry.samples(meter))
            assert isinstance(sot, sample.Sample)


import unittest

from openstack.telemetry.v2 import sample
from openstack.tests.functional import base


@unittest.skipUnless(base.service_exists(service_type="metering"),
                     "Metering service does not exist")
class TestSample(base.BaseFunctionalTest):

    def test_list(self):
        for meter in self.conn.telemetry.meters():
            for sot in self.conn.telemetry.samples(meter):
                assert isinstance(sot, sample.Sample)

Fix the telemetry sample test
Fix the telemetry sample test

This test works fine on devstack, but on the test gate not all
the meters have samples, so only iterate over them if there are
samples.

Partial-bug: #1665495

Change-Id: I8f327737a53194aeba08925391f1976f1b506aa0

  
  import unittest
  
  from openstack.telemetry.v2 import sample
  from openstack.tests.functional import base
  
  
  @unittest.skipUnless(base.service_exists(service_type="metering"),
                       "Metering service does not exist")
  class TestSample(base.BaseFunctionalTest):
  
      def test_list(self):
          for meter in self.conn.telemetry.meters():
-             sot = next(self.conn.telemetry.samples(meter))
+             for sot in self.conn.telemetry.samples(meter):
-             assert isinstance(sot, sample.Sample)
+                 assert isinstance(sot, sample.Sample)
  
Fix the telemetry sample test
## Code Before:

import unittest

from openstack.telemetry.v2 import sample
from openstack.tests.functional import base


@unittest.skipUnless(base.service_exists(service_type="metering"),
                     "Metering service does not exist")
class TestSample(base.BaseFunctionalTest):

    def test_list(self):
        for meter in self.conn.telemetry.meters():
            sot = next(self.conn.telemetry.samples(meter))
            assert isinstance(sot, sample.Sample)

## Instruction:
Fix the telemetry sample test
## Code After:

import unittest

from openstack.telemetry.v2 import sample
from openstack.tests.functional import base


@unittest.skipUnless(base.service_exists(service_type="metering"),
                     "Metering service does not exist")
class TestSample(base.BaseFunctionalTest):

    def test_list(self):
        for meter in self.conn.telemetry.meters():
            for sot in self.conn.telemetry.samples(meter):
                assert isinstance(sot, sample.Sample)
