def test_data_returns_ip_address_configuration_information(self): interface = factory_models.InterfaceFactory() ip1 = factory_models.IpAddressFactory(interface_id=interface.id) ip2 = factory_models.IpAddressFactory(interface_id=interface.id) data = views.InterfaceConfigurationView(interface).data() self.assertEqual(len(data['ip_addresses']), 2) self.assertItemsEqual(data['ip_addresses'], views.IpConfigurationView(ip1, ip2).data())
def test_data_returns_block_ip_info(self): block1 = factory_models.IpBlockFactory() block2 = factory_models.IpBlockFactory() interface = factory_models.InterfaceFactory(vif_id_on_device="123") ip1 = factory_models.IpAddressFactory(ip_block_id=block1.id, interface_id=interface.id) ip2 = factory_models.IpAddressFactory(ip_block_id=block2.id, interface_id=interface.id) expected_ip1_config = _ip_data(ip1, block1) expected_ip2_config = _ip_data(ip2, block2) ip_configuration_view = views.IpConfigurationView(ip1, ip2) self.assertEqual(expected_ip1_config, ip_configuration_view.data()[0]) self.assertEqual(expected_ip2_config, ip_configuration_view.data()[1])
def test_data_returns_deallocated_ip_info(self): block = factory_models.IpBlockFactory() interface = factory_models.InterfaceFactory(vif_id_on_device="123") ip = factory_models.IpAddressFactory(ip_block_id=block.id, interface_id=interface.id) ip.deallocate() deallocated_ip = models.IpAddress.find(ip.id) expected_ip_config = _ip_data(deallocated_ip, block) ip_configuration_view = views.IpConfigurationView(deallocated_ip) self.assertEqual(expected_ip_config, ip_configuration_view.data()[0])
def test_data_returns_route_info(self): block = factory_models.IpBlockFactory() interface = factory_models.InterfaceFactory(vif_id_on_device="123") route1 = factory_models.IpRouteFactory(source_block_id=block.id) route2 = factory_models.IpRouteFactory(source_block_id=block.id) ip = factory_models.IpAddressFactory(ip_block_id=block.id, interface_id=interface.id) expected_ip_config_routes = [_route_data(route1), _route_data(route2)] ip_configuration_view = views.IpConfigurationView(ip).data()[0] ip1_config_routes = ip_configuration_view['ip_block'].pop('ip_routes') self.assertItemsEqual(expected_ip_config_routes, ip1_config_routes)
def test_deallocated_ips_get_deleted(self): block = factory_models.PublicIpBlockFactory() ip = factory_models.IpAddressFactory(ip_block_id=block.id) block.deallocate_ip(ip.address) days = config.Config.get('keep_deallocated_ips_for_days') self._push_back_deallocated_date(ip, days) script = tests.melange_bin_path('melange-delete-deallocated-ips') config_file = tests.test_config_file() functional.execute("{0} --config-file={1}".format(script, config_file)) self.assertIsNone(models.IpAddress.get(ip.id))