def test_get_server_private_ip(self, mock_list_networks, mock_list_subnets, mock_has_service): mock_has_service.return_value = True mock_list_subnets.return_value = SUBNETS_WITH_NAT mock_list_networks.return_value = [{ 'id': 'test-net-id', 'name': 'test-net-name' }] srv = meta.obj_to_dict( fakes.FakeServer(id='test-id', name='test-name', status='ACTIVE', addresses={ 'private': [{ 'OS-EXT-IPS:type': 'fixed', 'addr': PRIVATE_V4, 'version': 4 }], 'public': [{ 'OS-EXT-IPS:type': 'floating', 'addr': PUBLIC_V4, 'version': 4 }] })) self.assertEqual(PRIVATE_V4, meta.get_server_private_ip(srv, self.cloud)) mock_has_service.assert_called_with('network') mock_list_networks.assert_called_once_with()
def test_get_server_internal_provider_ipv4_neutron(self, mock_list_networks, mock_list_subnets, mock_has_service): # Testing Clouds with Neutron mock_has_service.return_value = True mock_list_subnets.return_value = SUBNETS_WITH_NAT mock_list_networks.return_value = [{ 'id': 'test-net-id', 'name': 'test-net', 'router:external': False, 'provider:network_type': 'vxlan', 'provider:physical_network': None, }] srv = meta.obj_to_dict( fakes.FakeServer( id='test-id', name='test-name', status='ACTIVE', addresses={'test-net': [{ 'addr': PRIVATE_V4, 'version': 4 }]}, )) self.assertIsNone( meta.get_server_external_ipv4(cloud=self.cloud, server=srv)) int_ip = meta.get_server_private_ip(cloud=self.cloud, server=srv) self.assertEqual(PRIVATE_V4, int_ip)
def test_get_server_internal_provider_ipv4_neutron( self, mock_list_networks, mock_list_subnets, mock_has_service): # Testing Clouds with Neutron mock_has_service.return_value = True mock_list_subnets.return_value = SUBNETS_WITH_NAT mock_list_networks.return_value = [{ 'id': 'test-net-id', 'name': 'test-net', 'router:external': False, 'provider:network_type': 'vxlan', 'provider:physical_network': None, }] srv = meta.obj_to_dict(fakes.FakeServer( id='test-id', name='test-name', status='ACTIVE', addresses={'test-net': [{ 'addr': PRIVATE_V4, 'version': 4}]}, )) self.assertIsNone( meta.get_server_external_ipv4(cloud=self.cloud, server=srv)) int_ip = meta.get_server_private_ip(cloud=self.cloud, server=srv) self.assertEqual(PRIVATE_V4, int_ip)
def test_get_server_private_ip(self, mock_search_networks, mock_has_service): mock_has_service.return_value = True mock_search_networks.return_value = [{ 'id': 'test-net-id', 'name': 'test-net-name' }] srv = meta.obj_to_dict( fakes.FakeServer(id='test-id', name='test-name', status='ACTIVE', addresses={ 'private': [{ 'OS-EXT-IPS:type': 'fixed', 'addr': PRIVATE_V4, 'version': 4 }], 'public': [{ 'OS-EXT-IPS:type': 'floating', 'addr': PUBLIC_V4, 'version': 4 }] })) cloud = shade.openstack_cloud(validate=False) self.assertEqual(PRIVATE_V4, meta.get_server_private_ip(srv, cloud)) mock_has_service.assert_called_with('network') mock_search_networks.assert_called_with( filters={'router:external': False})
def test_get_server_private_ip(self): self.register_uris([ dict(method='GET', uri='https://network.example.com/v2.0/networks.json', json={ 'networks': [{ 'id': 'test-net-id', 'name': 'test-net-name' }] }), dict(method='GET', uri='https://network.example.com/v2.0/subnets.json', json={'subnets': SUBNETS_WITH_NAT}) ]) srv = fakes.make_fake_server(server_id='test-id', name='test-name', status='ACTIVE', addresses={ 'private': [{ 'OS-EXT-IPS:type': 'fixed', 'addr': PRIVATE_V4, 'version': 4 }], 'public': [{ 'OS-EXT-IPS:type': 'floating', 'addr': PUBLIC_V4, 'version': 4 }] }) self.assertEqual(PRIVATE_V4, meta.get_server_private_ip(srv, self.cloud)) self.assert_calls()
def test_get_server_internal_provider_ipv4_neutron(self): # Testing Clouds with Neutron self.register_uris([ dict(method='GET', uri='https://network.example.com/v2.0/networks.json', json={ 'networks': [{ 'id': 'test-net-id', 'name': 'test-net', 'router:external': False, 'provider:network_type': 'vxlan', 'provider:physical_network': None, }] }), dict(method='GET', uri='https://network.example.com/v2.0/subnets.json', json={'subnets': SUBNETS_WITH_NAT}) ]) srv = fakes.make_fake_server( server_id='test-id', name='test-name', status='ACTIVE', addresses={'test-net': [{ 'addr': PRIVATE_V4, 'version': 4 }]}, ) self.assertIsNone( meta.get_server_external_ipv4(cloud=self.cloud, server=srv)) int_ip = meta.get_server_private_ip(cloud=self.cloud, server=srv) self.assertEqual(PRIVATE_V4, int_ip) self.assert_calls()
def test_get_server_internal_provider_ipv4_neutron(self): # Testing Clouds with Neutron self.register_uris([ dict(method='GET', uri='https://network.example.com/v2.0/networks.json', json={'networks': [{ 'id': 'test-net-id', 'name': 'test-net', 'router:external': False, 'provider:network_type': 'vxlan', 'provider:physical_network': None, }]}), dict(method='GET', uri='https://network.example.com/v2.0/subnets.json', json={'subnets': SUBNETS_WITH_NAT}) ]) srv = fakes.make_fake_server( server_id='test-id', name='test-name', status='ACTIVE', addresses={'test-net': [{ 'addr': PRIVATE_V4, 'version': 4}]}, ) self.assertIsNone( meta.get_server_external_ipv4(cloud=self.cloud, server=srv)) int_ip = meta.get_server_private_ip(cloud=self.cloud, server=srv) self.assertEqual(PRIVATE_V4, int_ip) self.assert_calls()
def test_get_server_multiple_private_ip(self): self.register_uris([ dict(method='GET', uri='https://network.example.com/v2.0/networks.json', json={'networks': [{ 'id': 'test-net-id', 'name': 'test-net'}]} ), dict(method='GET', uri='https://network.example.com/v2.0/subnets.json', json={'subnets': SUBNETS_WITH_NAT}) ]) shared_mac = '11:22:33:44:55:66' distinct_mac = '66:55:44:33:22:11' srv = fakes.make_fake_server( server_id='test-id', name='test-name', status='ACTIVE', addresses={'test-net': [{'OS-EXT-IPS:type': 'fixed', 'OS-EXT-IPS-MAC:mac_addr': distinct_mac, 'addr': '10.0.0.100', 'version': 4}, {'OS-EXT-IPS:type': 'fixed', 'OS-EXT-IPS-MAC:mac_addr': shared_mac, 'addr': '10.0.0.101', 'version': 4}], 'public': [{'OS-EXT-IPS:type': 'floating', 'OS-EXT-IPS-MAC:mac_addr': shared_mac, 'addr': PUBLIC_V4, 'version': 4}]} ) self.assertEqual( '10.0.0.101', meta.get_server_private_ip(srv, self.cloud)) self.assert_calls()
def test_get_server_private_ip(self): self.register_uris([ dict(method='GET', uri='https://network.example.com/v2.0/networks.json', json={'networks': [{ 'id': 'test-net-id', 'name': 'test-net-name'}]} ), dict(method='GET', uri='https://network.example.com/v2.0/subnets.json', json={'subnets': SUBNETS_WITH_NAT}) ]) srv = fakes.make_fake_server( server_id='test-id', name='test-name', status='ACTIVE', addresses={'private': [{'OS-EXT-IPS:type': 'fixed', 'addr': PRIVATE_V4, 'version': 4}], 'public': [{'OS-EXT-IPS:type': 'floating', 'addr': PUBLIC_V4, 'version': 4}]} ) self.assertEqual( PRIVATE_V4, meta.get_server_private_ip(srv, self.cloud)) self.assert_calls()
def test_get_server_private_ip(self, mock_search_networks, mock_search_ports, mock_has_service): mock_has_service.return_value = True mock_search_ports.return_value = [{ 'network_id': 'test-net-id', 'fixed_ips': [{ 'ip_address': PRIVATE_V4 }], 'device_id': 'test-id' }] mock_search_networks.return_value = [{'id': 'test-net-id'}] srv = meta.obj_to_dict( fakes.FakeServer(id='test-id', name='test-name', status='ACTIVE')) cloud = shade.openstack_cloud() self.assertEqual(PRIVATE_V4, meta.get_server_private_ip(srv, cloud)) mock_has_service.assert_called_once_with('network') mock_search_ports.assert_called_once_with( filters={'device_id': 'test-id'}) mock_search_networks.assert_called_once_with(filters={ 'router:external': False, 'shared': False })
def _cleanup_ips(self, server): exception_list = list() fixed_ip = meta.get_server_private_ip(server) for ip in self.user_cloud.list_floating_ips(): if (ip.get('fixed_ip', None) == fixed_ip or ip.get('fixed_ip_address', None) == fixed_ip): try: self.user_cloud.delete_floating_ip(ip['id']) except Exception as e: exception_list.append(str(e)) continue if exception_list: # Raise an error: we must make users aware that something went # wrong raise OpenStackCloudException('\n'.join(exception_list))
def _cleanup_ips(self, server): exception_list = list() fixed_ip = meta.get_server_private_ip(server) for ip in self.cloud.list_floating_ips(): if (ip.get('fixed_ip', None) == fixed_ip or ip.get('fixed_ip_address', None) == fixed_ip): try: self.cloud.delete_floating_ip(ip['id']) except Exception as e: exception_list.append(str(e)) continue if exception_list: # Raise an error: we must make users aware that something went # wrong raise OpenStackCloudException('\n'.join(exception_list))
def test_get_server_private_ip(self, mock_search_networks, mock_search_ports, mock_has_service): mock_has_service.return_value = True mock_search_ports.return_value = [{ 'network_id': 'test-net-id', 'fixed_ips': [{'ip_address': PRIVATE_V4}], 'device_id': 'test-id' }] mock_search_networks.return_value = [{'id': 'test-net-id'}] srv = meta.obj_to_dict(fakes.FakeServer( id='test-id', name='test-name', status='ACTIVE')) cloud = shade.openstack_cloud() self.assertEqual(PRIVATE_V4, meta.get_server_private_ip(srv, cloud)) mock_has_service.assert_called_once_with('network') mock_search_ports.assert_called_once_with( filters={'device_id': 'test-id'} ) mock_search_networks.assert_called_once_with( filters={'router:external': False, 'shared': False} )
def test_get_server_private_ip( self, mock_list_networks, mock_list_subnets, mock_has_service): mock_has_service.return_value = True mock_list_subnets.return_value = SUBNETS_WITH_NAT mock_list_networks.return_value = [{ 'id': 'test-net-id', 'name': 'test-net-name' }] srv = meta.obj_to_dict(fakes.FakeServer( id='test-id', name='test-name', status='ACTIVE', addresses={'private': [{'OS-EXT-IPS:type': 'fixed', 'addr': PRIVATE_V4, 'version': 4}], 'public': [{'OS-EXT-IPS:type': 'floating', 'addr': PUBLIC_V4, 'version': 4}]} )) self.assertEqual( PRIVATE_V4, meta.get_server_private_ip(srv, self.cloud)) mock_has_service.assert_called_with('network') mock_list_networks.assert_called_once_with()
def test_get_server_private_ip( self, mock_search_networks, mock_has_service): mock_has_service.return_value = True mock_search_networks.return_value = [{ 'id': 'test-net-id', 'name': 'test-net-name' }] srv = meta.obj_to_dict(fakes.FakeServer( id='test-id', name='test-name', status='ACTIVE', addresses={'private': [{'OS-EXT-IPS:type': 'fixed', 'addr': PRIVATE_V4, 'version': 4}], 'public': [{'OS-EXT-IPS:type': 'floating', 'addr': PUBLIC_V4, 'version': 4}]} )) cloud = shade.openstack_cloud(validate=False) self.assertEqual(PRIVATE_V4, meta.get_server_private_ip(srv, cloud)) mock_has_service.assert_called_with('network') mock_search_networks.assert_called_with( filters={'router:external': False} )
def test_get_server_ip(self): srv = meta.obj_to_dict(FakeServer()) self.assertEqual(PRIVATE_V4, meta.get_server_private_ip(srv, self.cloud)) self.assertEqual(PUBLIC_V4, meta.get_server_external_ipv4(self.cloud, srv))
def test_get_server_ip(self): srv = meta.obj_to_dict(FakeServer()) self.assertEqual( PRIVATE_V4, meta.get_server_private_ip(srv, self.cloud)) self.assertEqual( PUBLIC_V4, meta.get_server_external_ipv4(self.cloud, srv))
def test_get_server_ip(self): srv = FakeServer() self.assertEqual(PRIVATE_V4, meta.get_server_private_ip(srv)) self.assertEqual(PUBLIC_V4, meta.get_server_public_ip(srv))
def test_get_server_ip(self): srv = FakeServer() self.assertEqual(PRIVATE_V4, meta.get_server_private_ip(srv)) self.assertEqual(PUBLIC_V4, meta.get_server_public_ip(srv))
def test_get_server_ip(self): srv = meta.obj_to_dict(FakeServer()) cloud = shade.openstack_cloud(validate=False) self.assertEqual(PRIVATE_V4, meta.get_server_private_ip(srv, cloud)) self.assertEqual(PUBLIC_V4, meta.get_server_external_ipv4(cloud, srv))