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.node_for_check_create_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) # retry in save configuration fake_client.create_vdc_network = mock.MagicMock( return_value=( True, self.generate_task( vcloud_plugin_common.TASK_STATUS_SUCCESS ) ) ) self.prepere_gatway_busy_retry(fake_client, fake_ctx) network.create(ctx=fake_ctx) self.check_retry_realy_called(fake_ctx) runtime_properties = fake_ctx.instance.runtime_properties self.assertTrue(runtime_properties[network.SKIP_CREATE_NETWORK]) # success in create_vdc_network 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)