Exemplo n.º 1
0
 def setUp(self):
     # objects
     self.customer = structure_factories.CustomerFactory()
     self.project = structure_factories.ProjectFactory(customer=self.customer)
     self.cloud = factories.CloudFactory(customer=self.customer)
     self.membership = factories.CloudProjectMembershipFactory(cloud=self.cloud, project=self.project)
     self.active_ip = factories.FloatingIPFactory(status='ACTIVE', cloud_project_membership=self.membership)
     self.down_ip = factories.FloatingIPFactory(status='DOWN', cloud_project_membership=self.membership)
     self.other_ip = factories.FloatingIPFactory(status='UNDEFINED')
     # users
     self.staff = structure_factories.UserFactory(is_staff=True)
     self.owner = structure_factories.UserFactory()
     self.customer.add_user(self.owner, models.CustomerRole.OWNER)
     self.admin = structure_factories.UserFactory()
     self.project.add_user(self.admin, models.ProjectRole.ADMINISTRATOR)
     self.user = structure_factories.UserFactory()
Exemplo n.º 2
0
 def test_pull_floating_ips_deletes_staled_ips(self):
     staled_ip = factories.FloatingIPFactory(
         backend_id='qqqq', cloud_project_membership=self.membership)
     # when
     self.backend.pull_floating_ips(self.membership)
     # then
     self.assertFalse(
         FloatingIP.objects.filter(id=staled_ip.id).exists(),
         'Staled floating ip should be deleted')
Exemplo n.º 3
0
    def test_assigned_floating_ip_becomes_active(self):
        nova = mock.Mock()
        nova.server.add_floating_ip = mock.Mock()

        floating_ip = factories.FloatingIPFactory(status='DOWN')
        self.backend.assign_floating_ip_to_instance(nova, factories.InstanceFactory(), floating_ip)
        self.assertTrue(
            FloatingIP.objects.filter(id=floating_ip.id, status='ACTIVE').exists()
        )
Exemplo n.º 4
0
    def test_assigned_floating_ip_is_added_to_instance(self):
        nova = mock.Mock()
        nova.server.add_floating_ip = mock.Mock()

        floating_ip = factories.FloatingIPFactory(status='DOWN')
        instance = factories.InstanceFactory()
        self.backend.assign_floating_ip_to_instance(nova, instance, floating_ip)
        self.assertTrue(
            Instance.objects.filter(uuid=instance.uuid, external_ips=floating_ip.address).exists()
        )
Exemplo n.º 5
0
 def test_pull_floating_ips_updates_existing_ips(self):
     backend_ip = self.floating_ips[0]
     nc_floating_ip = factories.FloatingIPFactory(
         backend_id=backend_ip['id'], cloud_project_membership=self.membership)
     # when
     self.backend.pull_floating_ips(self.membership)
     # then
     reread_ip = FloatingIP.objects.get(id=nc_floating_ip.id)
     backend_ip = self.floating_ips[0]
     self.assertEqual(reread_ip.address, backend_ip['floating_ip_address'])
     self.assertEqual(reread_ip.status, backend_ip['status'])
     self.assertEqual(reread_ip.backend_id, backend_ip['id'])
Exemplo n.º 6
0
    def test_floating_ip_is_released_after_instance_deletion(self):
        instance = factories.InstanceFactory(state=Instance.States.OFFLINE)
        factories.FloatingIPFactory(
            cloud_project_membership=instance.cloud_project_membership,
            address=instance.external_ips,
            status='ACTIVE')
        self.backend._wait_for_instance_deletion = mock.Mock(return_value=True)
        self.backend.delete_instance(instance)

        floating_ip = FloatingIP.objects.get(
            cloud_project_membership=instance.cloud_project_membership,
            address=instance.external_ips)
        self.assertEqual(floating_ip.status, 'DOWN')
Exemplo n.º 7
0
    def setUp(self):
        self.template = factories.TemplateFactory()
        self.flavor = factories.FlavorFactory()
        self.project = structure_factories.ProjectFactory()
        self.ssh_public_key = factories.SshPublicKeyFactory()
        self.membership = factories.CloudProjectMembershipFactory(
            cloud=self.flavor.cloud,
            project=self.project,
        )

        factories.ImageFactory(template=self.template, cloud=self.flavor.cloud)
        factories.FloatingIPFactory(status='DOWN',
                                    cloud_project_membership=self.membership,
                                    address='10.10.10.10')