def test_none_cidr_returned(self): mock_client = Mock() test_neutron_network_service.neutron_client.Client = Mock(return_value=mock_client) mock_client.create_subnet = Mock(return_value={'subnet': 'subnet success'}) mock_return_subnets = {'subnets': [{'cidr': '10.0.0.0/24', 'id': 'test-id-1'}, {'cidr': '10.0.1.0/24', 'id': 'test-id-2'}]} test_reserved_subnets = '10.0.0.0/8, 172.16.0.0/12 , 192.168.0.0/16' mock_client.list_subnets = Mock(return_value=mock_return_subnets) result = self.network_service._get_unused_cidr(client=mock_client, cp_resvd_cidrs=test_reserved_subnets, logger=self.mock_logger) self.assertEqual(result, None)
def test_create_floating_ip_returns_None(self): mock_client = Mock() test_neutron_network_service.neutron_client.Client = Mock(return_value=mock_client) test_network_id = 'test_network_id' test_subnet_id = 'test_subnet_id' test_result_subnet_dict = {'subnets': [{'network_id':test_network_id}]} mock_client.list_subnets = Mock(return_value=test_result_subnet_dict) mock_client.create_floatingip = Mock(return_value={}) result = self.network_service.create_floating_ip(openstack_session=self.openstack_session, floating_ip_subnet_id=test_subnet_id, logger=self.mock_logger) floating_ip_call_dict = {'floatingip': {'floating_network_id':test_network_id, 'subnet_id':test_subnet_id}} mock_client.create_floatingip.assert_called_with(floating_ip_call_dict) self.assertEqual(result, None)
def test_create_and_attach_subnet_to_net_success(self): test_net_id = 'test-net-id' mock_client = Mock() test_neutron_network_service.neutron_client.Client = Mock(return_value=mock_client) mock_client.create_subnet = Mock(return_value={'subnet':'subnet success'}) mock_return_subnets = {'subnets':[{'cidr': '192.168.1.0/24', 'id':'test-id-1'}, {'cidr': '192.168.1.0/24', 'id': 'test-id-2'}]} test_reserved_subnets = '10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/24' mock_client.list_subnets = Mock(return_value=mock_return_subnets) cp_resource_model = Mock() cp_resource_model.reserved_networks = test_reserved_subnets # self.network_service._get_unused_cidr = Mock(return_value = '10.0.0.0/24') result = self.network_service.create_and_attach_subnet_to_net(openstack_session=self.openstack_session, cp_resource_model=cp_resource_model, net_id=test_net_id, logger=self.mock_logger) self.assertEqual(result, 'subnet success')