Exemple #1
0
class PluginMissingInstanceTagTestCase(unittest.TestCase):

    def setUp(self):
        self.plugin = MissingInstanceTagPlugin()
        self.assertEqual(self.plugin.plugin_name, 'missingtag')

    def test_run(self, *mocks):

        eddaclient = Mock()
        eddaclient._since = 200

        def ret_list(args):
            return [
                {'imageId': 'ami-1', 'instanceId': 'a', 'launchTime': 400, "tags": [{"key": "Name", "value": "tag1"}]},
                {'imageId': 'ami-2', 'instanceId': 'b', 'launchTime': 600,
                    "tags": [{"key": "service_name", "value": "foo"}]},
                {'imageId': 'ami-3', 'instanceId': 'c', 'launchTime': 800, "tags":
                    [{"key": "Name", "value": "tag1"}, {"key": "service_name", "value": "foo"}]},
            ]

        m = Mock()
        m.query = Mock(side_effect=ret_list)
        eddaclient.clean = Mock(return_value=m)
        self.plugin.init(eddaclient, Mock(), {})

        # run the tested method
        self.assertEqual(self.plugin.run(), [{'details': ['n/a'], 'id': 'a', 'plugin_name': 'missingtag'}])

        m.query.assert_has_calls([call('/api/v2/view/instances;_expand')])
Exemple #2
0
class PluginMissingInstanceTagTestCase(unittest.TestCase):
    def setUp(self):
        self.plugin = MissingInstanceTagPlugin()
        self.assertEqual(self.plugin.plugin_name, "missingtag")

    def test_run(self, *mocks):
        instance_enricher = InstanceEnricher(Mock())
        eddaclient = Mock()
        eddaclient._since = 200

        def ret_list(args):
            return [
                {"imageId": "ami-1", "instanceId": "a", "launchTime": 400, "tags": [{"key": "Name", "value": "tag1"}]},
                {
                    "imageId": "ami-2",
                    "instanceId": "b",
                    "launchTime": 600,
                    "tags": [{"key": "service_name", "value": "foo"}],
                },
                {
                    "imageId": "ami-3",
                    "instanceId": "c",
                    "launchTime": 800,
                    "tags": [{"key": "Name", "value": "tag1"}, {"key": "service_name", "value": "foo"}],
                },
            ]

        m = Mock()
        m.query = Mock(side_effect=ret_list)
        eddaclient.clean = Mock(return_value=m)
        self.plugin.init(eddaclient, Mock(), {}, instance_enricher)

        # run the tested method
        result = self.plugin.run()

        self.assertEqual(1, len(result))
        result = result[0]
        self.assertEqual("tag1", result["id"])  # service_type became the new id, which in this case is the Name tag
        self.assertEqual(1, len(result["details"]))
        self.assertIn("instanceId", result["details"][0])

        m.query.assert_has_calls([call("/api/v2/view/instances;_expand")])
class PluginMissingInstanceTagTestCase(unittest.TestCase):
    def setUp(self):
        self.plugin = MissingInstanceTagPlugin()
        self.assertEqual(self.plugin.plugin_name, "missingtag")

    def test_run(self, *mocks):

        eddaclient = Mock()
        eddaclient._since = 200

        def ret_list(args):
            return [
                {"imageId": "ami-1", "instanceId": "a", "launchTime": 400, "tags": [{"key": "Name", "value": "tag1"}]},
                {
                    "imageId": "ami-2",
                    "instanceId": "b",
                    "launchTime": 600,
                    "tags": [{"key": "service_name", "value": "foo"}],
                },
                {
                    "imageId": "ami-3",
                    "instanceId": "c",
                    "launchTime": 800,
                    "tags": [{"key": "Name", "value": "tag1"}, {"key": "service_name", "value": "foo"}],
                },
            ]

        m = Mock()
        m.query = Mock(side_effect=ret_list)
        eddaclient.clean = Mock(return_value=m)
        self.plugin.init(eddaclient, Mock(), {})

        # run the tested method
        self.assertEqual(self.plugin.run(), [{"details": ["n/a"], "id": "a", "plugin_name": "missingtag"}])

        m.query.assert_has_calls([call("/api/v2/view/instances;_expand")])
Exemple #4
0
 def setUp(self):
     self.plugin = MissingInstanceTagPlugin()
     self.assertEqual(self.plugin.plugin_name, 'missingtag')
 def setUp(self):
     self.plugin = MissingInstanceTagPlugin()
     self.assertEqual(self.plugin.plugin_name, "missingtag")
Exemple #6
0
class PluginMissingInstanceTagTestCase(unittest.TestCase):
    def setUp(self):
        self.plugin = MissingInstanceTagPlugin()
        self.assertEqual(self.plugin.plugin_name, 'missingtag')

    def test_run(self, *mocks):
        instance_enricher = InstanceEnricher(Mock())
        eddaclient = Mock()
        eddaclient._since = 200

        def ret_list(args):
            return [
                {
                    'imageId': 'ami-1',
                    'instanceId': 'a',
                    'launchTime': 400,
                    "tags": [{
                        "key": "Name",
                        "value": "tag1"
                    }]
                },
                {
                    'imageId': 'ami-2',
                    'instanceId': 'b',
                    'launchTime': 600,
                    "tags": [{
                        "key": "service_name",
                        "value": "foo"
                    }]
                },
                {
                    'imageId':
                    'ami-3',
                    'instanceId':
                    'c',
                    'launchTime':
                    800,
                    "tags": [{
                        "key": "Name",
                        "value": "tag1"
                    }, {
                        "key": "service_name",
                        "value": "foo"
                    }]
                },
            ]

        m = Mock()
        m.query = Mock(side_effect=ret_list)
        eddaclient.clean = Mock(return_value=m)
        self.plugin.init(eddaclient, Mock(), {}, instance_enricher)

        # run the tested method
        result = self.plugin.run()

        self.assertEqual(1, len(result))
        result = result[0]
        self.assertEqual(
            "tag1", result["id"]
        )  # service_type became the new id, which in this case is the Name tag
        self.assertEqual(1, len(result["details"]))
        self.assertIn("instanceId", result["details"][0])

        m.query.assert_has_calls([call('/api/v2/view/instances;_expand')])