コード例 #1
0
    def test_create_firewall_rule(self):
        network = Network(self.config['config'],
                          self.ctx.logger,
                          self.config['network'])
        networks = network.list()
        item = utils.get_item_from_gcp_response(
            'name', self.config['network']['name'], networks)
        self.assertIsNone(item)

        firewall = FirewallRule(self.config['config'],
                                self.ctx.logger,
                                self.config['firewall'],
                                self.config['config']['network'])
        firewall_rules = firewall.list()
        item = utils.get_item_from_gcp_response('name',
                                                firewall.name,
                                                firewall_rules)
        self.assertIsNone(item)

        network.create()

        networks = network.list()
        item = utils.get_item_from_gcp_response(
            'name', self.config['network']['name'], networks)
        self.assertIsNotNone(item)

        firewall.create()

        firewall_rules = firewall.list()
        item = utils.get_item_from_gcp_response(
            'name',
            firewall.name,
            firewall_rules)
        self.assertIsNotNone(item)

        firewall.delete()

        firewall_rules = firewall.list()
        item = utils.get_item_from_gcp_response(
            'name',
            firewall.name,
            firewall_rules)
        self.assertIsNone(item)

        network.delete()

        networks = network.list()
        item = utils.get_item_from_gcp_response(
            'name', self.config['network']['name'], networks)
        self.assertIsNone(item)
コード例 #2
0
    def test_tag_firewall(self):
        network = Network(self.config['config'],
                          self.ctx.logger,
                          self.config['network'])
        network.create()

        firewall_rule = dict(self.config['firewall'])
        source_tag = 'source-tag'
        target_tag = 'target-tag'
        firewall_rule['sourceTags'] = [source_tag]
        firewall_rule['targetTags'] = [target_tag]
        firewall = FirewallRule(self.config['config'],
                                self.ctx.logger,
                                firewall_rule,
                                self.config['config']['network'])
        firewall.create()
        firewall_name = firewall.name
        firewalls = firewall.list()
        item = utils.get_item_from_gcp_response('name',
                                                firewall_name,
                                                firewalls)
        self.assertEqual(source_tag, find_in_list(source_tag,
                                                  item['sourceTags']))
        self.assertEqual(target_tag, find_in_list(target_tag,
                                                  item['targetTags']))

        firewall.firewall = self.config['firewall']
        firewall.firewall['name'] = firewall_name
        firewall.update()
        firewalls = firewall.list()
        item = utils.get_item_from_gcp_response('name',
                                                firewall_rule['name'],
                                                firewalls)
        self.assertIsNone(find_in_list(source_tag, item.get('sourceTags', [])))
        self.assertIsNone(find_in_list(target_tag, item.get('targetTags', [])))

        firewall.firewall = firewall_rule
        firewall.firewall['name'] = firewall_name
        firewall.update()
        firewalls = firewall.list()
        item = utils.get_item_from_gcp_response('name',
                                                firewall_rule['name'],
                                                firewalls)
        self.assertEqual(source_tag, find_in_list(source_tag,
                                                  item['sourceTags']))
        self.assertEqual(target_tag, find_in_list(target_tag,
                                                  item['targetTags']))
        firewall.delete()
        network.delete()
コード例 #3
0
    def test_create_firewall_rule(self):
        network = Network(self.config['config'], self.ctx.logger,
                          self.config['network'])
        networks = network.list()
        item = utils.get_item_from_gcp_response('name',
                                                self.config['network']['name'],
                                                networks)
        self.assertIsNone(item)

        firewall = FirewallRule(self.config['config'], self.ctx.logger,
                                self.config['firewall'],
                                self.config['config']['network'])
        firewall_rules = firewall.list()
        item = utils.get_item_from_gcp_response('name', firewall.name,
                                                firewall_rules)
        self.assertIsNone(item)

        network.create()

        networks = network.list()
        item = utils.get_item_from_gcp_response('name',
                                                self.config['network']['name'],
                                                networks)
        self.assertIsNotNone(item)

        firewall.create()

        firewall_rules = firewall.list()
        item = utils.get_item_from_gcp_response('name', firewall.name,
                                                firewall_rules)
        self.assertIsNotNone(item)

        firewall.delete()

        firewall_rules = firewall.list()
        item = utils.get_item_from_gcp_response('name', firewall.name,
                                                firewall_rules)
        self.assertIsNone(item)

        network.delete()

        networks = network.list()
        item = utils.get_item_from_gcp_response('name',
                                                self.config['network']['name'],
                                                networks)
        self.assertIsNone(item)
コード例 #4
0
    def test_tag_firewall(self):
        network = Network(self.config['config'], self.ctx.logger,
                          self.config['network'])
        network.create()

        firewall_rule = dict(self.config['firewall'])
        source_tag = 'source-tag'
        target_tag = 'target-tag'
        firewall_rule['sourceTags'] = [source_tag]
        firewall_rule['targetTags'] = [target_tag]
        firewall = FirewallRule(self.config['config'], self.ctx.logger,
                                firewall_rule,
                                self.config['config']['network'])
        firewall.create()
        firewall_name = firewall.name
        firewalls = firewall.list()
        item = utils.get_item_from_gcp_response('name', firewall_name,
                                                firewalls)
        self.assertEqual(source_tag,
                         find_in_list(source_tag, item['sourceTags']))
        self.assertEqual(target_tag,
                         find_in_list(target_tag, item['targetTags']))

        firewall.firewall = self.config['firewall']
        firewall.firewall['name'] = firewall_name
        firewall.update()
        firewalls = firewall.list()
        item = utils.get_item_from_gcp_response('name', firewall_rule['name'],
                                                firewalls)
        self.assertIsNone(find_in_list(source_tag, item.get('sourceTags', [])))
        self.assertIsNone(find_in_list(target_tag, item.get('targetTags', [])))

        firewall.firewall = firewall_rule
        firewall.firewall['name'] = firewall_name
        firewall.update()
        firewalls = firewall.list()
        item = utils.get_item_from_gcp_response('name', firewall_rule['name'],
                                                firewalls)
        self.assertEqual(source_tag,
                         find_in_list(source_tag, item['sourceTags']))
        self.assertEqual(target_tag,
                         find_in_list(target_tag, item['targetTags']))
        firewall.delete()
        network.delete()
コード例 #5
0
    def test_create_network(self):
        network = Network(self.config['config'], self.ctx.logger,
                          self.config['network'])
        networks = network.list()
        item = utils.get_item_from_gcp_response('name', network.name, networks)
        self.assertIsNone(item)
        self.ctx.logger.info(str(network.create))
        network.create()

        networks = network.list()
        item = utils.get_item_from_gcp_response('name', network.name, networks)
        self.assertIsNotNone(item)

        network.delete()

        networks = network.list()
        item = utils.get_item_from_gcp_response('name',
                                                self.config['network']['name'],
                                                networks)
        self.assertIsNone(item)
コード例 #6
0
    def test_create_network(self):
        network = Network(self.config['config'],
                          self.ctx.logger,
                          self.config['network'])
        networks = network.list()
        item = utils.get_item_from_gcp_response(
            'name', network.name, networks)
        self.assertIsNone(item)
        self.ctx.logger.info(str(network.create))
        network.create()

        networks = network.list()
        item = utils.get_item_from_gcp_response(
            'name', network.name, networks)
        self.assertIsNotNone(item)

        network.delete()

        networks = network.list()
        item = utils.get_item_from_gcp_response(
            'name', self.config['network']['name'], networks)
        self.assertIsNone(item)