def test_creation_validation_separate_ips(self):
     # test separate ips
     fake_client = self.generate_client(vdc_networks=['secret_network'])
     with mock.patch('vcloud_plugin_common.VcloudAirClient.get',
                     mock.MagicMock(return_value=fake_client)):
         fake_ctx = self.generate_node_context(
             properties={
                 'use_external_resource': False,
                 'network': {
                     'dhcp': {
                         'dhcp_range': "10.1.1.10-10.1.1.255"
                     },
                     'static_range': "10.1.1.2-10.1.1.210",
                     'gateway_ip': "10.1.1.1",
                     'edge_gateway': 'gateway',
                     'name': 'private_network',
                     "netmask": '255.255.255.0',
                     "dns": ["8.8.8.8", "4.4.4.4"]
                 },
                 'vcloud_config': {
                     'vdc': 'vdc_name'
                 },
             },
             runtime_properties={'vcloud_network_name': 'secret_network'})
         fake_client.get_network = mock.MagicMock(return_value=None)
         with self.assertRaises(cfy_exc.NonRecoverableError):
             network.creation_validation(ctx=fake_ctx)
 def test_creation_validation_separate_ips(self):
     # test separate ips
     fake_client = self.generate_client(
         vdc_networks=['secret_network']
     )
     with mock.patch(
         'vcloud_plugin_common.VcloudAirClient.get',
         mock.MagicMock(return_value=fake_client)
     ):
         fake_ctx = self.generate_node_context(
             properties={
                 'use_external_resource': False,
                 'network': {
                     'dhcp': {
                         'dhcp_range': "10.1.1.10-10.1.1.255"
                     },
                     'static_range':  "10.1.1.2-10.1.1.210",
                     'gateway_ip': "10.1.1.1",
                     'edge_gateway': 'gateway',
                     'name': 'private_network',
                     "netmask": '255.255.255.0',
                     "dns": ["8.8.8.8", "4.4.4.4"]
                 },
                 'vcloud_config': {
                     'vdc': 'vdc_name'
                 },
             },
             runtime_properties={
                 'vcloud_network_name': 'secret_network'
             }
         )
         fake_client.get_network = mock.MagicMock(return_value=None)
         with self.assertRaises(cfy_exc.NonRecoverableError):
             network.creation_validation(ctx=fake_ctx)
    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(vdc_networks=['secret_network'])
     with mock.patch('vcloud_plugin_common.VcloudAirClient.get',
                     mock.MagicMock(return_value=fake_client)):
         # network not exist in node properties
         fake_ctx = self.generate_node_context(
             properties={
                 'use_external_resource': False,
                 'resource_id': 'secret_network'
             },
             runtime_properties={'vcloud_network_name': 'secret_network'})
         with self.assertRaises(cfy_exc.NonRecoverableError):
             network.creation_validation(ctx=fake_ctx)
         # network already exist
         fake_ctx = self.generate_node_context(
             properties={
                 'use_external_resource': False,
                 'resource_id': 'secret_network',
                 'network': {
                     'dhcp': {
                         'dhcp_range': "10.1.1.128-10.1.1.255"
                     },
                     'static_range': "10.1.1.2-10.1.1.127",
                     'gateway_ip': "10.1.1.1",
                     'edge_gateway': 'gateway',
                     'name': 'secret_network',
                     "netmask": '255.255.255.0',
                     "dns": ["8.8.8.8", "4.4.4.4"]
                 },
                 'vcloud_config': {
                     'vdc': 'vdc_name'
                 },
             },
             runtime_properties={'vcloud_network_name': 'secret_network'})
         fake_client.get_network = mock.MagicMock(return_value=True)
         with self.assertRaises(cfy_exc.NonRecoverableError):
             network.creation_validation(ctx=fake_ctx)
         fake_client.get_network.assert_called_with('vdc_name',
                                                    'secret_network')
         # use external
         fake_ctx = self.generate_node_context(
             properties={
                 'use_external_resource': True,
                 'resource_id': 'secret_network',
                 'network': {
                     'dhcp': {
                         'dhcp_range': "10.1.1.128-10.1.1.255"
                     },
                     'static_range': "10.1.1.2-10.1.1.127",
                     'gateway_ip': "10.1.1.1",
                     'edge_gateway': 'gateway',
                     'name': 'secret_network',
                     "netmask": '255.255.255.0',
                     "dns": ["8.8.8.8", "4.4.4.4"]
                 },
                 'vcloud_config': {
                     'vdc': 'vdc_name'
                 },
             },
             runtime_properties={'vcloud_network_name': 'secret_network'})
         network.creation_validation(ctx=fake_ctx)
 def test_creation_validation(self):
     fake_client = self.generate_client(
         vdc_networks=['secret_network']
     )
     with mock.patch(
         'vcloud_plugin_common.VcloudAirClient.get',
         mock.MagicMock(return_value=fake_client)
     ):
         # network not exist in node properties
         fake_ctx = self.generate_node_context(
             properties={
                 'use_external_resource': False,
                 'resource_id': 'secret_network'
             },
             runtime_properties={
                 'vcloud_network_name': 'secret_network'
             }
         )
         with self.assertRaises(cfy_exc.NonRecoverableError):
             network.creation_validation(ctx=fake_ctx)
         # network already exist
         fake_ctx = self.generate_node_context(
             properties={
                 'use_external_resource': False,
                 'resource_id': 'secret_network',
                 'network': {
                     'dhcp': {
                         'dhcp_range': "10.1.1.128-10.1.1.255"
                     },
                     'static_range':  "10.1.1.2-10.1.1.127",
                     'gateway_ip': "10.1.1.1",
                     'edge_gateway': 'gateway',
                     'name': 'secret_network',
                     "netmask": '255.255.255.0',
                     "dns": ["8.8.8.8", "4.4.4.4"]
                 },
                 'vcloud_config': {
                     'vdc': 'vdc_name'
                 },
             },
             runtime_properties={
                 'vcloud_network_name': 'secret_network'
             }
         )
         fake_client.get_network = mock.MagicMock(return_value=True)
         with self.assertRaises(cfy_exc.NonRecoverableError):
             network.creation_validation(ctx=fake_ctx)
         fake_client.get_network.assert_called_with(
             'vdc_name', 'secret_network'
         )
         # use external
         fake_ctx = self.generate_node_context(
             properties={
                 'use_external_resource': True,
                 'resource_id': 'secret_network',
                 'network': {
                     'dhcp': {
                         'dhcp_range': "10.1.1.128-10.1.1.255"
                     },
                     'static_range':  "10.1.1.2-10.1.1.127",
                     'gateway_ip': "10.1.1.1",
                     'edge_gateway': 'gateway',
                     'name': 'secret_network',
                     "netmask": '255.255.255.0',
                     "dns": ["8.8.8.8", "4.4.4.4"]
                 },
                 'vcloud_config': {
                     'vdc': 'vdc_name'
                 },
             },
             runtime_properties={
                 'vcloud_network_name': 'secret_network'
             }
         )
         network.creation_validation(ctx=fake_ctx)