def test_validation(self):
        self.ctx.node.properties.update(
            {'floatingip': self.test_config['floatingip']})
        with mock.patch('network_plugin.floatingip.ctx', self.ctx):
            floatingip.creation_validation()

        self.ctx.node.properties.update(
            {'floatingip': self.test_config['floatingip_auto']})
        with mock.patch('network_plugin.floatingip.ctx', self.ctx):
            floatingip.creation_validation()

        self.ctx.node.properties.update(
            {'private_key_path': os.path.realpath(__file__)})
        with mock.patch('network_plugin.keypair.ctx', self.ctx):
            keypair.creation_validation()

        self.ctx.node.properties.update({
            "resource_id":
            self.test_config['network']['name'],
            "network":
            self.test_config['network'],
            "use_external_resource":
            False
        })
        with mock.patch('network_plugin.network.ctx', self.ctx):
            network.creation_validation()

        self.ctx.node.properties.update({
            'port': {
                'network': self.test_config['management_network'],
                'ip_allocation_mode': 'dhcp',
                'primary_interface': True
            }
        })
        with mock.patch('network_plugin.port.ctx', self.ctx):
            port.creation_validation()

        self.ctx.node.properties.update({
            "nat":
            self.test_config['public_nat']['nat'],
            "rules":
            self.test_config['public_nat']['rules_net']
        })
        with mock.patch('network_plugin.public_nat.ctx', self.ctx):
            public_nat.creation_validation()

        self.ctx.node.properties.update(self.test_config['security_group'])
        with mock.patch('network_plugin.security_group.ctx', self.ctx):
            security_group.creation_validation()
    def test_validation(self):
        self.ctx.node.properties.update(
            {'floatingip': self.test_config['floatingip']})
        with mock.patch('network_plugin.floatingip.ctx', self.ctx):
            floatingip.creation_validation()

        self.ctx.node.properties.update(
            {'floatingip': self.test_config['floatingip_auto']})
        with mock.patch('network_plugin.floatingip.ctx', self.ctx):
            floatingip.creation_validation()

        self.ctx.node.properties.update(
            {'private_key_path': os.path.realpath(__file__)})
        with mock.patch('network_plugin.keypair.ctx', self.ctx):
            keypair.creation_validation()

        self.ctx.node.properties.update(
            {"resource_id": self.test_config['network']['name'],
             "network": self.test_config['network'],
             "use_external_resource": False})
        with mock.patch('network_plugin.network.ctx', self.ctx):
            network.creation_validation()

        self.ctx.node.properties.update(
            {'port': {
                'network': self.test_config['management_network'],
                'ip_allocation_mode': 'dhcp',
                'primary_interface': True}})
        with mock.patch('network_plugin.port.ctx', self.ctx):
            port.creation_validation()

        self.ctx.node.properties.update(
            {"nat": self.test_config['public_nat']['nat'],
             "rules": self.test_config['public_nat']['rules_net']})
        with mock.patch('network_plugin.public_nat.ctx', self.ctx):
            public_nat.creation_validation()

        self.ctx.node.properties.update(self.test_config['security_group'])
        with mock.patch('network_plugin.security_group.ctx', self.ctx):
            security_group.creation_validation()
 def test_creation_validation(self):
     fake_client = self.generate_client()
     # no floating_ip
     fake_ctx = self.generate_node_context(
         properties={
             'vcloud_config': {
                 'vdc': 'vdc_name'
             }
         }
     )
     with mock.patch(
         'vcloud_plugin_common.VcloudAirClient.get',
         mock.MagicMock(return_value=fake_client)
     ):
         with self.assertRaises(cfy_exc.NonRecoverableError):
             floatingip.creation_validation(ctx=fake_ctx)
     # no edge gateway
     fake_ctx = self.generate_node_context(
         properties={
             'vcloud_config': {
                 'vdc': 'vdc_name'
             },
             'floatingip': {
                 'some_field': 'some value'
             }
         }
     )
     with mock.patch(
         'vcloud_plugin_common.VcloudAirClient.get',
         mock.MagicMock(return_value=fake_client)
     ):
         with self.assertRaises(cfy_exc.NonRecoverableError):
             floatingip.creation_validation(ctx=fake_ctx)
     # with edge gateway, but wrong ip
     fake_ctx = self.generate_node_context(
         properties={
             'vcloud_config': {
                 'vdc': 'vdc_name'
             },
             'floatingip': {
                 'edge_gateway': 'gateway',
                 network_plugin.PUBLIC_IP: 'some'
             }
         }
     )
     with mock.patch(
         'vcloud_plugin_common.VcloudAirClient.get',
         mock.MagicMock(return_value=fake_client)
     ):
         with self.assertRaises(cfy_exc.NonRecoverableError):
             floatingip.creation_validation(ctx=fake_ctx)
     # with edge gateway, ip from pool
     fake_ctx = self.generate_node_context(properties={
         'vcloud_config': {
             'vdc': 'vdc_name'
         },
         'floatingip': {
             'edge_gateway': 'gateway',
             'service_type': vcloud_plugin_common.ONDEMAND_SERVICE_TYPE
         }
     })
     fake_client._vdc_gateway.get_public_ips = mock.MagicMock(
         return_value=['10.18.1.1']
     )
     with mock.patch(
         'vcloud_plugin_common.VcloudAirClient.get',
         mock.MagicMock(return_value=fake_client)
     ):
         floatingip.creation_validation(ctx=fake_ctx)
     # with some free ip
     fake_ctx = self.generate_node_context(properties={
         'vcloud_config': {
             'vdc': 'vdc_name'
         },
         'floatingip': {
             'edge_gateway': 'gateway',
             network_plugin.PUBLIC_IP: '10.10.1.2',
             'service_type': vcloud_plugin_common.SUBSCRIPTION_SERVICE_TYPE
         }
     })
     fake_client._vdc_gateway.get_public_ips = mock.MagicMock(return_value=[
         '10.1.1.1', '10.1.1.2'
     ])
     rule_inlist = self.generate_nat_rule(
         'DNAT', '10.1.1.1', 'any', '123.1.1.1', '11', 'TCP'
     )
     fake_client.get_nat_rules = mock.MagicMock(
         return_value=[rule_inlist]
     )
     with mock.patch(
         'vcloud_plugin_common.VcloudAirClient.get',
         mock.MagicMock(return_value=fake_client)
     ):
         floatingip.creation_validation(ctx=fake_ctx)
示例#4
0
 def test_creation_validation(self):
     fake_client = self.generate_client()
     # no floating_ip
     fake_ctx = self.generate_node_context(
         properties={'vcloud_config': {
             'vdc': 'vdc_name'
         }})
     with mock.patch('vcloud_plugin_common.VcloudAirClient.get',
                     mock.MagicMock(return_value=fake_client)):
         with self.assertRaises(cfy_exc.NonRecoverableError):
             floatingip.creation_validation(ctx=fake_ctx)
     # no edge gateway
     fake_ctx = self.generate_node_context(
         properties={
             'vcloud_config': {
                 'vdc': 'vdc_name'
             },
             'floatingip': {
                 'some_field': 'some value'
             }
         })
     with mock.patch('vcloud_plugin_common.VcloudAirClient.get',
                     mock.MagicMock(return_value=fake_client)):
         with self.assertRaises(cfy_exc.NonRecoverableError):
             floatingip.creation_validation(ctx=fake_ctx)
     # with edge gateway, but wrong ip
     fake_ctx = self.generate_node_context(
         properties={
             'vcloud_config': {
                 'vdc': 'vdc_name'
             },
             'floatingip': {
                 'edge_gateway': 'gateway',
                 network_plugin.PUBLIC_IP: 'some'
             }
         })
     with mock.patch('vcloud_plugin_common.VcloudAirClient.get',
                     mock.MagicMock(return_value=fake_client)):
         with self.assertRaises(cfy_exc.NonRecoverableError):
             floatingip.creation_validation(ctx=fake_ctx)
     # with edge gateway, ip from pool
     fake_ctx = self.generate_node_context(
         properties={
             'vcloud_config': {
                 'vdc': 'vdc_name'
             },
             'floatingip': {
                 'edge_gateway': 'gateway',
                 'service_type': vcloud_plugin_common.ONDEMAND_SERVICE_TYPE
             }
         })
     fake_client._vdc_gateway.get_public_ips = mock.MagicMock(
         return_value=['10.18.1.1'])
     with mock.patch('vcloud_plugin_common.VcloudAirClient.get',
                     mock.MagicMock(return_value=fake_client)):
         floatingip.creation_validation(ctx=fake_ctx)
     # with some free ip
     fake_ctx = self.generate_node_context(
         properties={
             'vcloud_config': {
                 'vdc': 'vdc_name'
             },
             'floatingip': {
                 'edge_gateway': 'gateway',
                 network_plugin.PUBLIC_IP: '10.10.1.2',
                 'service_type':
                 vcloud_plugin_common.SUBSCRIPTION_SERVICE_TYPE
             }
         })
     fake_client._vdc_gateway.get_public_ips = mock.MagicMock(
         return_value=['10.1.1.1', '10.1.1.2'])
     rule_inlist = self.generate_nat_rule('DNAT', '10.1.1.1', 'any',
                                          '123.1.1.1', '11', 'TCP')
     fake_client.get_nat_rules = mock.MagicMock(return_value=[rule_inlist])
     with mock.patch('vcloud_plugin_common.VcloudAirClient.get',
                     mock.MagicMock(return_value=fake_client)):
         floatingip.creation_validation(ctx=fake_ctx)