def test_create_exist_same_network(self):
     fake_client = self.generate_client(
         vdc_networks=['secret_network']
     )
     with mock.patch(
         'vcloud_plugin_common.VcloudAirClient.get',
         mock.MagicMock(return_value=fake_client)
     ):
         # exist same network
         fake_ctx = self.generate_node_context(
             properties={
                 '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'
                 },
                 'use_external_resource': False,
                 'resource_id': 'secret_network'
             },
             runtime_properties={
                 'vcloud_network_name': 'secret_network'
             }
         )
         fake_client.get_network = mock.MagicMock(return_value=None)
         with self.assertRaises(cfy_exc.NonRecoverableError):
             network.create(ctx=fake_ctx)
 def test_create_exist_same_network(self):
     fake_client = self.generate_client(vdc_networks=['secret_network'])
     with mock.patch('vcloud_plugin_common.VcloudAirClient.get',
                     mock.MagicMock(return_value=fake_client)):
         # exist same network
         fake_ctx = self.generate_node_context(
             properties={
                 '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'
                 },
                 'use_external_resource': False,
                 'resource_id': 'secret_network'
             },
             runtime_properties={'vcloud_network_name': 'secret_network'})
         fake_client.get_network = mock.MagicMock(return_value=None)
         with self.assertRaises(cfy_exc.NonRecoverableError):
             network.create(ctx=fake_ctx)
 def test_orgnetwork_create_delete(self):
     self.assertNotIn(
         self.net_name,
         network._get_network_list(self.vca_client, self.org_name))
     start_pools = len(self.get_pools())
     network.create()
     self.assertIn(
         self.net_name,
         network._get_network_list(self.vca_client, self.org_name))
     self.assertEqual(start_pools + 1, len(self.get_pools()))
     network.delete()
     self.assertNotIn(
         self.net_name,
         network._get_network_list(self.vca_client, self.org_name))
     self.assertEqual(start_pools, len(self.get_pools()))
 def test_orgnetwork_create_delete(self):
     self.assertNotIn(self.net_name,
                      network._get_network_list(self.vca_client,
                                                self.org_name))
     start_pools = len(self.get_pools())
     network.create()
     self.assertIn(self.net_name,
                   network._get_network_list(self.vca_client,
                                             self.org_name))
     self.assertEqual(start_pools + 1, len(self.get_pools()))
     network.delete()
     self.assertNotIn(self.net_name,
                      network._get_network_list(self.vca_client,
                                                self.org_name))
     self.assertEqual(start_pools, len(self.get_pools()))
 def test_create(self):
     fake_client = self.generate_client()
     with mock.patch('vcloud_plugin_common.VcloudAirClient.get',
                     mock.MagicMock(return_value=fake_client)):
         fake_ctx = self.generate_node_context(
             properties={
                 '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'
                 },
                 'use_external_resource': False
             },
             runtime_properties={'vcloud_network_name': 'secret_network'})
         # error in create_vdc_network
         with self.assertRaises(cfy_exc.NonRecoverableError):
             network.create(ctx=fake_ctx)
         fake_client.create_vdc_network.assert_called_with(
             'vdc_name', 'secret_network', 'gateway', '10.1.1.2',
             '10.1.1.127', '10.1.1.1', '255.255.255.0', '8.8.8.8',
             '4.4.4.4', None)
         # error in create_vdc_network
         task = self.generate_task(vcloud_plugin_common.TASK_STATUS_ERROR)
         fake_client.create_vdc_network = mock.MagicMock(
             return_value=(True, task))
         with self.assertRaises(cfy_exc.NonRecoverableError):
             network.create(ctx=fake_ctx)
         # success in create_vdc_network
         fake_client.create_vdc_network = mock.MagicMock(return_value=(
             True,
             self.generate_task(vcloud_plugin_common.TASK_STATUS_SUCCESS)))
         self.set_services_conf_result(
             fake_client._vdc_gateway,
             vcloud_plugin_common.TASK_STATUS_SUCCESS)
         network.create(ctx=fake_ctx)
         # error in get gateway
         fake_client.get_gateway = mock.MagicMock(return_value=None)
         with self.assertRaises(cfy_exc.NonRecoverableError):
             network.create(ctx=fake_ctx)
         # use external
         fake_ctx = self.generate_node_context(
             properties={
                 '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'
                 },
                 'use_external_resource': True,
                 'resource_id': 'secret_network'
             },
             runtime_properties={'vcloud_network_name': 'secret_network'})
         network.create(ctx=fake_ctx)
         # not extist network
         fake_ctx = self.generate_node_context(
             properties={
                 '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'
                 },
                 'use_external_resource': True,
                 'resource_id': 'secret_network'
             },
             runtime_properties={'vcloud_network_name': 'secret_network'})
         fake_client.get_network = mock.MagicMock(return_value=None)
         with self.assertRaises(cfy_exc.NonRecoverableError):
             network.create(ctx=fake_ctx)
 def test_create(self):
     fake_client = self.generate_client()
     with mock.patch(
         'vcloud_plugin_common.VcloudAirClient.get',
         mock.MagicMock(return_value=fake_client)
     ):
         fake_ctx = self.generate_node_context(
             properties={
                 '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'
                 },
                 'use_external_resource': False
             },
             runtime_properties={
                 'vcloud_network_name': 'secret_network'
             }
         )
         # error in create_vdc_network
         with self.assertRaises(cfy_exc.NonRecoverableError):
             network.create(ctx=fake_ctx)
         fake_client.create_vdc_network.assert_called_with(
             'vdc_name', 'secret_network', 'gateway', '10.1.1.2',
             '10.1.1.127', '10.1.1.1', '255.255.255.0', '8.8.8.8',
             '4.4.4.4', None
         )
         # error in create_vdc_network
         task = self.generate_task(
             vcloud_plugin_common.TASK_STATUS_ERROR
         )
         fake_client.create_vdc_network = mock.MagicMock(
             return_value=(True, task)
         )
         with self.assertRaises(cfy_exc.NonRecoverableError):
             network.create(ctx=fake_ctx)
         # success in create_vdc_network
         fake_client.create_vdc_network = mock.MagicMock(
             return_value=(
                 True,
                 self.generate_task(
                     vcloud_plugin_common.TASK_STATUS_SUCCESS
                )
             )
         )
         self.set_services_conf_result(
             fake_client._vdc_gateway,
             vcloud_plugin_common.TASK_STATUS_SUCCESS
         )
         network.create(ctx=fake_ctx)
         # error in get gateway
         fake_client.get_gateway = mock.MagicMock(return_value=None)
         with self.assertRaises(cfy_exc.NonRecoverableError):
             network.create(ctx=fake_ctx)
         # use external
         fake_ctx = self.generate_node_context(
             properties={
                 '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'
                 },
                 'use_external_resource': True,
                 'resource_id': 'secret_network'
             },
             runtime_properties={
                 'vcloud_network_name': 'secret_network'
             }
         )
         network.create(ctx=fake_ctx)
         # not extist network
         fake_ctx = self.generate_node_context(
             properties={
                 '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'
                 },
                 'use_external_resource': True,
                 'resource_id': 'secret_network'
             },
             runtime_properties={
                 'vcloud_network_name': 'secret_network'
             }
         )
         fake_client.get_network = mock.MagicMock(return_value=None)
         with self.assertRaises(cfy_exc.NonRecoverableError):
             network.create(ctx=fake_ctx)
 def _create_network(self):
     with contextlib.nested(
             mock.patch('network_plugin.network.ctx', self.network_ctx),
             mock.patch('vcloud_plugin_common.ctx', self.network_ctx)):
         network.create()
示例#8
0
 def _create_network(self):
     with contextlib.nested(
             mock.patch('network_plugin.network.ctx', self.network_ctx),
             mock.patch('vcloud_plugin_common.ctx', self.network_ctx)):
         network.create()