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): 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_1 = CloudProjectFactory(project_id='project_id1') self.cloud_project_2 = CloudProjectFactory(project_id='project_id2') self.cloud_project_3 = CloudProjectFactory(project_id='project_os_id1') self.host = CloudHostFactory(host_id='host_id1', parent=self.cloud_project_1, cloudflavor=self.cloud_flavor[1]) IPAddress.objects.create(base_object=self.host, address='2.2.3.4') IPAddress.objects.create(base_object=self.host, address='1.2.3.4') DataCenterAsset.objects.create( hostname='hypervisor_os1.dcn.net', model=asset_model, ) self.ironic_serial_number_param = 'serial_number' self.ralph_serial_number_param = 'sn' self.ralph_client = RalphClient('openstack', self.ironic_serial_number_param, self.ralph_serial_number_param) self.openstack_client = RalphOpenStackInfrastructureClient( self.cloud_provider.name)
def test_unused_cloud_flavor_can_be_deleted(self): # given cloud_flavor = CloudFlavorFactory() # when url = reverse('cloudflavor-detail', args=(cloud_flavor.pk, )) resp = self.client.delete(url) # then self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT) self.assertRaises(CloudFlavor.DoesNotExist, cloud_flavor.refresh_from_db)
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_used_cloud_flavor_can_be_deleted_with_force(self): # given cloud_flavor = CloudFlavorFactory() CloudHostFactory(cloudflavor=cloud_flavor) # when url = reverse('cloudflavor-detail', args=(cloud_flavor.pk, )) data = {'force': True} resp = self.client.delete(url, data=data) # then self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT) self.assertRaises(CloudFlavor.DoesNotExist, cloud_flavor.refresh_from_db)
def test_delete_cloud_flavor_returns_409_if_is_used_by_cloud_hosts(self): # given cloud_flavor = CloudFlavorFactory() CloudHostFactory(cloudflavor=cloud_flavor) # when url = reverse('cloudflavor-detail', args=(cloud_flavor.pk, )) resp = self.client.delete(url) # then self.assertEqual(resp.status_code, status.HTTP_409_CONFLICT) self.assertIn('Cloud flavor is in use and hence is not deletable.', resp.data['detail']) self.assertTrue( CloudFlavor.objects.filter(pk=cloud_flavor.pk).exists())
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 test_cleanup_doesnt_remove_cloud_flavours_with_assignments(self): flavor = CloudFlavorFactory(flavor_id='im_not_here', name='im_not_here') CloudHostFactory(host_id='host_id123', cloudflavor=flavor) openstack_flavors = copy(OPENSTACK_FLAVORS) openstack_flavors.update({flavor.flavor_id: {"name": flavor.name}}) 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, incremental=True) self.ralph_client.perform_delete(OPENSTACK_DATA, OPENSTACK_FLAVORS, ralph_projects, ralph_flavors, servers_to_delete) try: CloudFlavor.objects.get(flavor_id='im_not_here') except ObjectDoesNotExist: self.fail('Flavor "im_not_here" was deleted.')