コード例 #1
0
    def setUp(self):
        super(BaseClusterCreateTest, self).setUp()
        self.fixture = fixtures.RancherFixture()
        self.url = factories.ClusterFactory.get_list_url()
        openstack_service_settings = openstack_factories.OpenStackServiceSettingsFactory(
            customer=self.fixture.customer
        )
        self.tenant = openstack_factories.TenantFactory(
            service_settings=openstack_service_settings
        )

        openstack_tenant_factories.FlavorFactory(settings=self.fixture.tenant_settings)
        image = openstack_tenant_factories.ImageFactory(
            settings=self.fixture.tenant_settings
        )
        self.default_security_group = openstack_tenant_factories.SecurityGroupFactory(
            name='default', settings=self.fixture.tenant_settings
        )
        self.fixture.settings.options['base_image_name'] = image.name
        self.fixture.settings.save()

        self.network = openstack_tenant_factories.NetworkFactory(
            settings=self.fixture.tenant_settings
        )
        self.subnet = openstack_tenant_factories.SubNetFactory(
            network=self.network, settings=self.fixture.tenant_settings
        )
        self.flavor = Flavor.objects.get(settings=self.fixture.tenant_settings)
        self.flavor.ram = 1024 * 8
        self.flavor.cores = 2
        self.flavor.save()
        self.fixture.settings.options['base_subnet_name'] = self.subnet.name
        self.fixture.settings.save()
コード例 #2
0
    def setUp(self):
        super(BaseClusterCreateTest, self).setUp()
        self.fixture = fixtures.RancherFixture()
        self.url = factories.ClusterFactory.get_list_url()
        openstack_service_settings = openstack_factories.OpenStackServiceSettingsFactory(
            customer=self.fixture.customer)
        openstack_service = openstack_factories.OpenStackServiceFactory(
            customer=self.fixture.customer,
            settings=openstack_service_settings)
        openstack_spl = openstack_factories.OpenStackServiceProjectLinkFactory(
            project=self.fixture.project, service=openstack_service)
        self.tenant = openstack_factories.TenantFactory(
            service_project_link=openstack_spl)

        settings = ServiceSettings.objects.get(scope=self.tenant)
        project = self.fixture.project
        instance_spl = OpenStackTenantServiceProjectLink.objects.get(
            project=project, service__settings=settings)

        openstack_tenant_factories.FlavorFactory(
            settings=instance_spl.service.settings)
        image = openstack_tenant_factories.ImageFactory(
            settings=instance_spl.service.settings)
        openstack_tenant_factories.SecurityGroupFactory(
            name='default', settings=instance_spl.service.settings)
        self.fixture.settings.options['base_image_name'] = image.name
        self.fixture.settings.save()

        network = openstack_tenant_factories.NetworkFactory(
            settings=instance_spl.service.settings)
        self.subnet = openstack_tenant_factories.SubNetFactory(
            network=network, settings=instance_spl.service.settings)
        self.fixture.settings.options['base_subnet_name'] = self.subnet.name
        self.fixture.settings.save()
コード例 #3
0
def _instance_data(user, instance=None):
    if instance is None:
        instance = factories.InstanceFactory()
    factories.FloatingIPFactory(settings=instance.service_settings,
                                runtime_state='DOWN')
    image = factories.ImageFactory(settings=instance.service_settings)
    flavor = factories.FlavorFactory(settings=instance.service_settings)
    ssh_public_key = structure_factories.SshPublicKeyFactory(user=user)
    subnet = factories.SubNetFactory(settings=instance.service_settings)
    return {
        'name':
        'test-host',
        'description':
        'test description',
        'flavor':
        factories.FlavorFactory.get_url(flavor),
        'image':
        factories.ImageFactory.get_url(image),
        'service_settings':
        factories.OpenStackTenantServiceSettingsFactory.get_url(
            instance.service_settings),
        'project':
        structure_factories.ProjectFactory.get_url(instance.project),
        'ssh_public_key':
        structure_factories.SshPublicKeyFactory.get_url(ssh_public_key),
        'system_volume_size':
        max(image.min_disk, 1024),
        'internal_ips_set': [{
            'subnet': factories.SubNetFactory.get_url(subnet)
        }],
    }
コード例 #4
0
    def test_subnet_update(self):
        openstack_subnet = openstack_factories.SubNetFactory(
            network=self.openstack_network,
            name='New subnet name',
            state=StateMixin.States.UPDATING,
        )
        subnet = factories.SubNetFactory(
            network=self.network,
            settings=self.service_settings,
            backend_id=openstack_subnet.backend_id,
        )

        openstack_subnet.set_ok()
        openstack_subnet.save()
        subnet.refresh_from_db()

        self.assertEqual(openstack_subnet.name, subnet.name)
        self.assertEqual(openstack_subnet.cidr, subnet.cidr)
        self.assertEqual(openstack_subnet.gateway_ip, subnet.gateway_ip)
        self.assertEqual(openstack_subnet.allocation_pools,
                         subnet.allocation_pools)
        self.assertEqual(openstack_subnet.ip_version, subnet.ip_version)
        self.assertEqual(openstack_subnet.enable_dhcp, subnet.enable_dhcp)
        self.assertEqual(openstack_subnet.dns_nameservers,
                         subnet.dns_nameservers)
コード例 #5
0
    def test_internal_ips_are_not_associated_with_instance_if_subnet_belongs_to_another_settings(
        self,
    ):
        subnet = factories.SubNetFactory()
        payload = self._get_valid_payload(
            internal_ips_set=[{'subnet': factories.SubNetFactory.get_url(subnet)}]
        )

        response = self.client.post(self.url, payload)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertIn('internal_ips_set', response.data)
コード例 #6
0
    def test_floating_ip_is_not_associated_with_an_instance_if_subnet_is_not_connected_to_the_instance(
        self,
    ):
        floating_ip = factories.FloatingIPFactory(
            settings=self.service_settings, runtime_state='DOWN'
        )
        subnet = factories.SubNetFactory(settings=self.service_settings)
        payload = self._get_valid_payload(
            floating_ips=[
                {
                    'url': factories.FloatingIPFactory.get_url(floating_ip),
                    'subnet': factories.SubNetFactory.get_url(subnet),
                }
            ]
        )

        response = self.client.post(self.url, payload)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertIn('floating_ips', response.data)
コード例 #7
0
    def test_floating_ip_is_not_associated_with_an_instance_if_it_belongs_to_different_settings(
        self,
    ):
        floating_ip = factories.FloatingIPFactory(runtime_state='DOWN')
        self.assertNotEqual(self.service_settings, floating_ip.settings)
        subnet = factories.SubNetFactory(settings=self.service_settings)
        payload = self._get_valid_payload(
            floating_ips=[
                {
                    'url': factories.FloatingIPFactory.get_url(floating_ip),
                    'subnet': factories.SubNetFactory.get_url(subnet),
                }
            ],
            internal_ips_set=[{'subnet': factories.SubNetFactory.get_url(subnet)}],
        )

        response = self.client.post(self.url, payload)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertIn('floating_ips', response.data)
コード例 #8
0
    def setUp(self):
        user = structure_factories.UserFactory(is_staff=True)
        self.client.force_authenticate(user=user)

        self.backup = factories.BackupFactory(state=models.Backup.States.OK)
        ss = self.backup.service_settings
        ss.options = {'external_network_id': uuid.uuid4().hex}
        ss.save()
        self.url = factories.BackupFactory.get_url(self.backup, 'restore')

        system_volume = self.backup.instance.volumes.get(bootable=True)
        self.disk_size = system_volume.size

        self.service_settings = self.backup.instance.service_settings
        self.service_settings.options = {'external_network_id': uuid.uuid4().hex}
        self.service_settings.save()
        self.valid_flavor = factories.FlavorFactory(
            disk=self.disk_size + 10, settings=self.service_settings
        )
        self.subnet = factories.SubNetFactory(settings=self.service_settings)
コード例 #9
0
    def test_floating_ip_is_associated_with_an_instance_if_floating_ip_is_in_DOWN_state(
        self,
    ):
        floating_ip = factories.FloatingIPFactory(
            settings=self.service_settings, runtime_state='ACTIVE'
        )
        subnet = factories.SubNetFactory(settings=self.service_settings)
        payload = self._get_valid_payload(
            floating_ips=[
                {
                    'url': factories.FloatingIPFactory.get_url(floating_ip),
                    'subnet': factories.SubNetFactory.get_url(subnet),
                }
            ],
            internal_ips_set=[{'subnet': factories.SubNetFactory.get_url(subnet)}],
        )

        response = self.client.post(self.url, payload)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data)
        self.assertIn('floating_ips', response.data)
コード例 #10
0
    def test_floating_ip_is_not_valid_if_it_is_already_assigned(self):
        subnet = factories.SubNetFactory(settings=self.service_settings)
        internal_ip = factories.InternalIPFactory(subnet=subnet)
        floating_ip = factories.FloatingIPFactory(
            internal_ip=internal_ip,
            settings=self.service_settings,
            runtime_state='ACTIVE',
        )

        payload = self._get_valid_payload(
            floating_ips=[
                {
                    'url': factories.FloatingIPFactory.get_url(floating_ip),
                    'subnet': factories.SubNetFactory.get_url(subnet),
                }
            ],
            internal_ips_set=[{'subnet': factories.SubNetFactory.get_url(subnet)}],
        )

        response = self.client.post(self.url, payload)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertIn('floating_ips', response.data)
コード例 #11
0
 def subnet(self):
     return factories.SubNetFactory(
         network=self.network,
         settings=self.openstack_tenant_service_settings)