def setUp(self):
        super(TestCeilometerClient, self).setUp()
        self.conf = cfg.ConfigOpts()
        self.useFixture(ConfFixture(self.conf))

        self.patches.extend([
            patch.object(
                KeystoneClient,
                "token",
                new=PropertyMock(return_value="fake-token")
            ),
            patch.object(
                KeystoneClient,
                "ceilometer_uri",
                new=PropertyMock(return_value="http://fake-ceilometer-ep:7777")
            ),
        ])

        self.client = CeilometerClient(
            auth_uri="http://fake-keystone-ep:1337",
            admin_user="******",
            admin_password="******",
            admin_tenant_name="fake_tenant",
        )

        for _patch in self.patches:
            _patch.start()
Example #2
0
    def setUp(self):
        super(TestCeilometerClient, self).setUp()
        self.conf = cfg.ConfigOpts()
        self.useFixture(ConfFixture(self.conf))

        self.patches.extend([
            patch.object(KeystoneClient,
                         "token",
                         new=PropertyMock(return_value="fake-token")),
            patch.object(KeystoneClient,
                         "ceilometer_uri",
                         new=PropertyMock(
                             return_value="http://fake-ceilometer-ep:7777")),
        ])

        self.client = CeilometerClient(
            auth_uri="http://fake-keystone-ep:1337",
            admin_user="******",
            admin_password="******",
            admin_tenant_name="fake_tenant",
        )

        for _patch in self.patches:
            _patch.start()
Example #3
0
class TestCeilometerClient(BaseTestCase):

    # patches to be applied for each test in this test suite
    patches = []

    def setUp(self):
        super(TestCeilometerClient, self).setUp()
        self.conf = cfg.ConfigOpts()
        self.useFixture(ConfFixture(self.conf))

        self.patches.extend([
            patch.object(KeystoneClient,
                         "token",
                         new=PropertyMock(return_value="fake-token")),
            patch.object(KeystoneClient,
                         "ceilometer_uri",
                         new=PropertyMock(
                             return_value="http://*****:*****@patch.object(json, "dumps", new=MagicMock(side_effect=lambda x: x))
    @patch.object(requests, "post", autopec=True)
    def test_ceilometer_send_valid_metric(self, m_post):
        m_post.return_value = MagicMock(status_code=200)

        fake_metric = OrderedDict([
            ("name", "compute.node.cpu.percent"),
            ("timestamp", "2015-08-04T15:15:45.703542"), ("unit", "%"),
            ("type", "gauge"), ("value", 97.9), ("resource_id", "res_id-fake"),
            ("host", "test_node"),
            ("resource_metadata",
             OrderedDict([("host", "test_node"),
                          ("title", "compute.node.cpu.percent")]))
        ])

        expected_metric = OrderedDict([
            ("name", "compute.node.cpu.percent"),
            ("timestamp", "2015-08-04T15:15:45.703542"),
            ("unit", "%"),
            ("type", "gauge"),
            ("volume", 97.9),
            ("host", "test_node"),
            ("user_id", ""),
            ("project_id", ""),
            ("resource_id", "res_id-fake"),
            ("resource_metadata",
             OrderedDict([
                 ("host", "test_node"),
                 ("title", "compute.node.cpu.percent"),
             ])),
        ])

        self.client.send(fake_metric)

        # Should check that the data send over via the Ceilometer client are OK
        m_post.assert_called_once_with(
            "http://*****:*****@patch.object(requests, "post", autopec=True)
    def test_ceilometer_send_invalid_metric(self, m_post):
        m_post.return_value = MagicMock(status_code=404)

        fake_metric = OrderedDict([
            ("name", "compute.node.cpu.percent"),
            ("timestamp", "2015-08-04T15:15:45.703542"),
            ("unit", "%"),
            ("type", "gauge"),
            ("value", "97.9"),  # A string instead of a numerical value
            ("resource_id", ""),
            ("host", "test_node"),
            ("resource_metadata",
             OrderedDict([("host", "test_node"),
                          ("title", "compute.node.cpu.percent")]))
        ])

        self.client.send(fake_metric)
class TestCeilometerClient(BaseTestCase):

    # patches to be applied for each test in this test suite
    patches = []

    def setUp(self):
        super(TestCeilometerClient, self).setUp()
        self.conf = cfg.ConfigOpts()
        self.useFixture(ConfFixture(self.conf))

        self.patches.extend([
            patch.object(
                KeystoneClient,
                "token",
                new=PropertyMock(return_value="fake-token")
            ),
            patch.object(
                KeystoneClient,
                "ceilometer_uri",
                new=PropertyMock(return_value="http://*****:*****@patch.object(json, "dumps", new=MagicMock(side_effect=lambda x: x))
    @patch.object(requests, "post", autopec=True)
    def test_ceilometer_send_valid_metric(self, m_post):
        m_post.return_value = MagicMock(status_code=200)

        fake_metric = OrderedDict([
            ("name", "compute.node.cpu.percent"),
            ("timestamp", "2015-08-04T15:15:45.703542"),
            ("unit", "%"),
            ("type", "gauge"),
            ("value", 97.9),
            ("resource_id", "res_id-fake"),
            ("host", "test_node"),
            ("resource_metadata", OrderedDict([
                ("host", "test_node"),
                ("title", "compute.node.cpu.percent")]))
        ])

        expected_metric = OrderedDict([
            ("name", "compute.node.cpu.percent"),
            ("timestamp", "2015-08-04T15:15:45.703542"),
            ("unit", "%"),
            ("type", "gauge"),
            ("volume", 97.9),
            ("host", "test_node"),
            ("user_id", ""),
            ("project_id", ""),
            ("resource_id", "res_id-fake"),
            ("resource_metadata", OrderedDict([
                ("host", "test_node"),
                ("title", "compute.node.cpu.percent"),
            ])),
        ])

        self.client.send(fake_metric)

        # Should check that the data send over via the Ceilometer client are OK
        m_post.assert_called_once_with(
            "http://*****:*****@patch.object(requests, "post", autopec=True)
    def test_ceilometer_send_invalid_metric(self, m_post):
        m_post.return_value = MagicMock(status_code=404)

        fake_metric = OrderedDict([
            ("name", "compute.node.cpu.percent"),
            ("timestamp", "2015-08-04T15:15:45.703542"),
            ("unit", "%"),
            ("type", "gauge"),
            ("value", "97.9"),  # A string instead of a numerical value
            ("resource_id", ""),
            ("host", "test_node"),
            ("resource_metadata", OrderedDict([
                ("host", "test_node"),
                ("title", "compute.node.cpu.percent")]))
        ])

        self.client.send(fake_metric)