def setUp(self): asset_model = DataCenterAssetModelFactory() self.cloud_provider = CloudProviderFactory(name='openstack') self.cloud_flavor = CloudFlavorFactory.create_batch(3) self.test_model = ComponentModel(name='delete_test') VirtualComponent( model=self.test_model, base_object=self.cloud_flavor[0] ) self.cloud_project = CloudProjectFactory(project_id='project_id1') CloudProjectFactory(project_id='project_id2') CloudProjectFactory(project_id='project_os_id1') host = CloudHostFactory( host_id='host_id1', parent=self.cloud_project, cloudflavor=self.cloud_flavor[1] ) IPAddress.objects.create(base_object=host, address='2.2.3.4') IPAddress.objects.create(base_object=host, address='1.2.3.4') DataCenterAsset.objects.create( hostname='hypervisor_os1.dcn.net', model=asset_model, ) self.cmd = Command() self.cmd._get_cloud_provider() self.cmd.openstack_projects = OPENSTACK_DATA self.cmd.openstack_flavors = OPENSTACK_FLAVOR self.cmd._get_ralph_data() self.cmd.ironic_serial_number_param = 'serial_number' self.cmd.ralph_serial_number_param = 'sn'
def setUp(self): self.service = ServiceFactory() self.service_env = ServiceEnvironmentFactory(service=self.service) self.cloud_project = CloudProjectFactory() self.cloud_host = CloudHostFactory(parent=self.cloud_project) self.custom_field_str = CustomField.objects.create( name='test str', type=CustomFieldTypes.STRING, default_value='xyz')
def test_filter_by_cloudproject_name(self): CloudProjectFactory(name='my-cloud-project') url = '{}?{}'.format( reverse('baseobject-list'), urlencode( {'name__startswith': 'my-cloud'} ) ) response = self.client.get(url, format='json') self.assertEqual(len(response.data['results']), 1)
def setUp(self): self.envs = EnvironmentFactory.create_batch(2) self.services = ServiceFactory.create_batch(2) self.service_env = [] for i in range(0, 2): self.service_env.append( ServiceEnvironment.objects.create(service=self.services[i], environment=self.envs[i])) self.cloud_provider = CloudProviderFactory(name='openstack') self.cloud_flavor = CloudFlavorFactory() self.cloud_project = CloudProjectFactory() self.cloud_host = CloudHostFactory(parent=self.cloud_project) self.test_cpu = ComponentModel.objects.create( name='vcpu1', cores=4, family='vCPU', type=ComponentType.processor, ) self.test_mem = ComponentModel.objects.create( name='1024 MiB vMEM', size='1024', type=ComponentType.memory, ) self.test_disk = ComponentModel.objects.create( name='4 GiB vDISK', size='4096', type=ComponentType.disk, ) VirtualComponent.objects.create( base_object=self.cloud_flavor, model=self.test_cpu, ) VirtualComponent.objects.create( base_object=self.cloud_flavor, model=self.test_mem, ) VirtualComponent.objects.create( base_object=self.cloud_flavor, model=self.test_disk, )
def setUp(self): super().setUp() self.envs = EnvironmentFactory.create_batch(2) self.services = ServiceFactory.create_batch(2) self.service_env = [] for i in range(0, 2): self.service_env.append(ServiceEnvironment.objects.create( service=self.services[i], environment=self.envs[i] )) self.service_env[0].service.business_owners = [self.user1] self.service_env[0].service.technical_owners = [self.user2] self.service_env[0].save() self.cloud_provider = CloudProviderFactory(name='openstack') self.cloud_flavor = CloudFlavorFactory() self.cloud_project = CloudProjectFactory( service_env=self.service_env[0] ) self.cloud_host = CloudHostFactory( parent=self.cloud_project, cloudflavor=self.cloud_flavor ) self.cloud_host2 = CloudHostFactory() self.test_cpu = ComponentModel.objects.create( name='vcpu1', cores=5, family='vCPU', type=ComponentType.processor, ) self.test_mem = ComponentModel.objects.create( name='2000 MiB vMEM', size='2000', type=ComponentType.memory, ) self.test_disk = ComponentModel.objects.create( name='4 GiB vDISK', size='4096', type=ComponentType.disk, ) VirtualComponent.objects.create( base_object=self.cloud_flavor, model=self.test_cpu, ) VirtualComponent.objects.create( base_object=self.cloud_flavor, model=self.test_mem, ) VirtualComponent.objects.create( base_object=self.cloud_flavor, model=self.test_disk, )
def test_cleanup_doesnt_remove_cloud_projects_with_children(self): project = CloudProjectFactory(project_id='im_not_here') host = CloudHostFactory(host_id='host_id123', parent=project, cloudflavor=self.cloud_flavor[1]) self.cmd._get_ralph_data() self.cmd._cleanup() try: CloudProject.objects.get(project_id='im_not_here') except ObjectDoesNotExist: self.fail('Project "im_not_here" was deleted.')
def test_cleanup_doesnt_remove_cloud_projects_with_different_provider(self): CloudProjectFactory( project_id='im_not_here', cloudprovider=CloudProviderFactory() ) self.cmd._get_ralph_data() self.cmd._cleanup() try: CloudProject.objects.get(project_id='im_not_here') except ObjectDoesNotExist: self.fail('Project "im_not_here" was deleted.')
def test_cleanup_doesnt_remove_cloud_projects_with_different_provider( self): CloudProjectFactory( project_id='im_not_here', cloudprovider=CloudProviderFactory(name='some_random_provider')) ralph_projects = self.ralph_client.get_ralph_servers_data( self.ralph_client.get_ralph_projects()) ralph_flavors = self.ralph_client.get_ralph_flavors() servers_to_delete = self.ralph_client.calculate_servers_to_delete( OPENSTACK_DATA, ralph_projects, ) self.ralph_client.perform_delete(OPENSTACK_DATA, OPENSTACK_FLAVORS, ralph_projects, ralph_flavors, servers_to_delete) try: CloudProject.objects.get(project_id='im_not_here') except ObjectDoesNotExist: self.fail('Project "im_not_here" was deleted.')
def test_cleanup_doesnt_remove_cloud_projects_with_children(self): project = CloudProjectFactory(project_id='im_not_here') CloudHostFactory(host_id='host_id123', parent=project, cloudflavor=self.cloud_flavor[1]) ralph_projects = self.ralph_client.get_ralph_servers_data( self.ralph_client.get_ralph_projects()) ralph_flavors = self.ralph_client.get_ralph_flavors() servers_to_delete = self.ralph_client.calculate_servers_to_delete( OPENSTACK_DATA, ralph_projects, ) self.ralph_client.perform_delete(OPENSTACK_DATA, OPENSTACK_FLAVORS, ralph_projects, ralph_flavors, servers_to_delete) try: CloudProject.objects.get(project_id='im_not_here') except ObjectDoesNotExist: self.fail('Project "im_not_here" was deleted.')
class OpenstackModelsTestCase(RalphTestCase): def setUp(self): self.envs = EnvironmentFactory.create_batch(2) self.services = ServiceFactory.create_batch(2) self.service_env = [] for i in range(0, 2): self.service_env.append( ServiceEnvironment.objects.create(service=self.services[i], environment=self.envs[i])) self.cloud_provider = CloudProviderFactory(name='openstack') self.cloud_flavor = CloudFlavorFactory() self.cloud_project = CloudProjectFactory() self.cloud_host = CloudHostFactory(parent=self.cloud_project) self.test_cpu = ComponentModel.objects.create( name='vcpu1', cores=4, family='vCPU', type=ComponentType.processor, ) self.test_mem = ComponentModel.objects.create( name='1024 MiB vMEM', size='1024', type=ComponentType.memory, ) self.test_disk = ComponentModel.objects.create( name='4 GiB vDISK', size='4096', type=ComponentType.disk, ) VirtualComponent.objects.create( base_object=self.cloud_flavor, model=self.test_cpu, ) VirtualComponent.objects.create( base_object=self.cloud_flavor, model=self.test_mem, ) VirtualComponent.objects.create( base_object=self.cloud_flavor, model=self.test_disk, ) @unpack @data( ('cores', 4), ('memory', 1024), ('disk', 4096), ) def test_cloudflavor_get_components(self, field, value): self.assertEqual(getattr(self.cloud_flavor, field), value) @unpack @data( ('cores', 8), ('memory', 2048), ('disk', 1024), ) def test_cloudflavor_set_components(self, key, value): setattr(self.cloud_flavor, key, value) self.assertEqual(getattr(self.cloud_flavor, key), value) def test_check_cloudhost_ip_addresses_setter(self): ips_count = IPAddress.objects.count() ip_addresses = ['10.0.0.1', '10.0.0.2'] ip_addresses2 = ['10.31.0.1', '10.30.0.0'] self.cloud_host.ip_addresses = ip_addresses self.assertEqual(set(self.cloud_host.ip_addresses), set(ip_addresses)) self.assertEqual(IPAddress.objects.count(), ips_count + 2) self.cloud_host.ip_addresses = ip_addresses2 self.assertEqual(set(self.cloud_host.ip_addresses), set(ip_addresses2)) # two IPs were removed, two were added self.assertEqual(IPAddress.objects.count(), ips_count + 2) def test_ip_hostname_update(self): ip_addresses = { '10.0.0.1': 'hostname1.mydc.net', '10.0.0.2': 'hostname2.mydc.net', } ip_addresses2 = { '10.0.0.1': 'hostname3.mydc.net', '10.0.0.3': 'hostname4.mydc.net', } self.cloud_host.ip_addresses = ip_addresses self.assertEqual(set(self.cloud_host.ip_addresses), set(ip_addresses)) self.assertEqual( IPAddress.objects.get(address='10.0.0.1').hostname, 'hostname1.mydc.net') self.assertEqual( IPAddress.objects.get(address='10.0.0.2').hostname, 'hostname2.mydc.net') self.cloud_host.ip_addresses = ip_addresses2 self.assertEqual( IPAddress.objects.get(address='10.0.0.1').hostname, 'hostname3.mydc.net') self.assertEqual( IPAddress.objects.get(address='10.0.0.3').hostname, 'hostname4.mydc.net') self.assertEqual(set(self.cloud_host.ip_addresses), set(ip_addresses2)) def test_service_env_inheritance_on_project_change(self): self.cloud_project.service_env = self.service_env[0] self.cloud_project.save() updated_host = CloudHost.objects.get(pk=self.cloud_host.id) self.assertEqual(updated_host.service_env, self.service_env[0]) def test_service_env_inheritance_on_host_creation(self): self.cloud_project.service_env = self.service_env[1] self.cloud_project.save() new_host = CloudHostFactory(host_id="new_host_id", parent=self.cloud_project) self.assertEqual(new_host.service_env, self.service_env[1])