Ejemplo n.º 1
0
    def test_resize_server_revert(self):
        """Verify that a re-sized server can be reverted."""

        # Resize the server and wait for it to finish
        new_flavor = self.os.flavors.get(2)
        self.server.resize(new_flavor)

        # Let the resize-confirm register or self.os.serves.get will
        # raise an exception
        time.sleep(2)

        # Create list of states
        states = utils.StatusTracker('active', 'resize-confirm')

        # Wait for server to transition to next state and make sure it
        # went to the correct one
        dtutil.assert_is(True,
                         states.waitForState(self.os.servers.get,
                                             'status', self.server))

        # Revert the resize
        self.server.revert_resize()

        # Check that the was reverted to its original flavor
        self.server = self.os.servers.get(self.server)
        dtutil.assert_equal(new_flavor.id, self.server.flavorId)
Ejemplo n.º 2
0
    def test_snap_and_restore(self):
        """Verify that a server is snapped and rebuilt from that snap"""

        states = utils.StatusTracker('active', 'queued', 'preparing',
                                     'saving', 'active')

        # Make a backup image for the server
        backup_image = self.os.images.create(server=self.server,
                                             name="backup")
        dtutil.assert_is(True,
                         states.waitForState(self.os.images.get,
                                             'status', backup_image))

        # wrap it in a try so that we can clean up afterwards
        try:
            dtutil.assert_equal(backup_image.name, "backup")

            # Finally, rebuild from the image
            states = utils.StatusTracker('active', 'build', 'active')
            self.os.servers.rebuild(self.server.id, backup_image.id)
            dtutil.assert_is(True,
                             states.waitForState(self.os.servers.get,
                                                 'status', self.server))
            created_server = self.os.servers.get(self.server.id)

            # This has the original image_id out of convention.
            image = self.os.images.get(created_server.imageId)
            dtutil.assert_equal(backup_image.name, image.name)
        finally:
            # delete the image
            self.glance_connection.delete_image(backup_image)
Ejemplo n.º 3
0
    def test_update_server_name(self):
        """Verify that a server's name can be modified."""

        server = self.server
        self.os.servers.update(server=server.id, name="modifiedName")

        # Verify the server's name has changed
        updated_server = self.os.servers.get(server)
        dtutil.assert_equal("modifiedName", updated_server.name)
Ejemplo n.º 4
0
    def test_get_server(self):
        """Test that the expected server details are returned."""

        # Verify the server fields are correct
        flavor = self.os.flavors.get(self.flavor)
        image = self.os.images.get(self.image)
        server = self.os.servers.get(self.server)
        dtutil.assert_equal(int(image.id), int(server.imageId))
        dtutil.assert_equal(int(flavor.id), int(server.flavorId))
Ejemplo n.º 5
0
    def test_create_server_image(self):
        """Verify a backup image for a server can be created."""

        # Set legal states
        states = utils.StatusTracker('active', 'queued', 'preparing',
                                     'saving', 'active')

        # Make a backup image for the server
        backup_image = self.os.images.create(server=self.server,
                                             name="backup")
        dtutil.assert_is(True,
                         states.waitForState(self.os.images.get,
                                             'status', backup_image))

        dtutil.assert_equal(backup_image.name, "backup")

        # Cleanup
        self.os.images.delete(backup_image)
Ejemplo n.º 6
0
    def test_list(self):
        """Test that images can be listed."""

        # See if we can retrieve the list of images
        images = self.os.images.list()

        # Do we have a list?
        dtutil.assert_not_equal(len(images), 0)

        # Let's see if our test image is in the list
        foundimg = False
        for img in images:
            if img.id == self._image_id:
                dtutil.assert_equal(img.name, self._image_name)
                dtutil.assert_equal(img.status, 'ACTIVE')
                foundimg = True

        # Did we actually find the image we were looking for?
        dtutil.assert_true(foundimg)
Ejemplo n.º 7
0
    def test_get(self):
        """Test that we can get the details of a given flavor."""

        # Check the flavors
        for exemplar in self.recognized_flavors.values():
            flav = self.os.flavors.get(exemplar['id'])

            # Check that all the details match
            dtutil.assert_equal(exemplar['id'], flav.id)
            dtutil.assert_equal(exemplar['name'], flav.name)
            dtutil.assert_equal(exemplar['ram'], flav.ram)
            dtutil.assert_equal(exemplar['disk'], flav.disk)
Ejemplo n.º 8
0
    def test_sample(self):
        """Test that we can do sample."""
        ## You don't *have* to declare a doc string, but it's good
        ## practice.

        ## Here we're making a "sample_call()", passing self.token as
        ## the authentication token.  For available calls and the
        ## order of arguments, check out ksapi.py.  The return value
        ## will be an httplib.HTTPResponse object with additional
        ## 'body' (str) and 'obj' (dict) attributes.  If a status code
        ## greater than or equal to 400 is returned from the other
        ## end, an exception will be raised; the response will be
        ## attached to the 'response' attribute of the exception, and
        ## the status will be on the 'status' attribute of the
        ## exception.  Note that redirects are followed.
        resp = self.ks.sample_call(self.token, 'argument 1', 'argument 2')

        # Verify that resp is correct
        util.assert_equal(resp.status, 200)
        util.assert_in('sample', resp.obj)
Ejemplo n.º 9
0
    def test_create_delete_server(self):
        """Verify that a server is created and that it is deleted."""

        # Setup
        server_name = self.randName()
        new_server = self.create_server(server_name, FLAGS.image, FLAGS.flavor)

        # Legal states...
        states = utils.StatusTracker("active", "build", "active")

        # Wait for server to transition to next state and make sure it
        # went to the correct one
        dtutil.assert_is(True, states.waitForState(self.os.servers.get, "status", new_server))

        # Verify the server was created correctly
        created_server = self.os.servers.get(new_server.id)
        dtutil.assert_equal(server_name, created_server.name)

        # Delete the server.  The delete testing is moved to
        # test_delete
        new_server.delete()
Ejemplo n.º 10
0
    def test_resize_server_confirm(self):
        """Verify that the flavor of a server can be changed."""

        # Resize the server and wait for it to finish
        new_flavor = self.os.flavors.get(2)
        self.server.resize(new_flavor)

        # Legal states...
        states = utils.StatusTracker('active', 'resize-confirm')

        # Wait for server to transition to next state and make sure it
        # went to the correct one
        dtutil.assert_is(True,
                         states.waitForState(self.os.servers.get,
                                             'status', self.server))

        # Confirm the resize
        self.server.confirm_resize()

        # Check that server's flavor has changed
        self.server = self.os.servers.get(self.server)
        dtutil.assert_equal(new_flavor.id, self.server.flavorId)
Ejemplo n.º 11
0
    def test_authenticate(self):
        """Test that we can authenticate using Keystone."""

        # Issue the authentication request
        resp = self.ks.authenticate(base.options.username,
                                    base.options.password)

        # Verify that resp is correct
        util.assert_equal(resp.status, 200)
        util.assert_in('auth', resp.obj)
        util.assert_in('token', resp.obj['auth'])
        util.assert_in('expires', resp.obj['auth']['token'])
        util.assert_in('id', resp.obj['auth']['token'])
        # util.assert_in('user', resp.obj['auth'])
        # util.assert_in('username', resp.obj['auth']['user'])
        # util.assert_in('tenantId', resp.obj['auth']['user'])
        # util.assert_equal(resp.obj['auth']['user']['username'],
        #                  base.options.username)

        # Now ensure we can revoke an authentication token
        auth_tok = resp.obj['auth']['token']['id']
        resp = self.ks.revoke_token(auth_tok, auth_tok)
        util.assert_equal(resp.status, 204)
Ejemplo n.º 12
0
    def test_rebuild_server(self):
        """Verify that a server is created, rebuilt, and then deleted."""

        # Trigger a rebuild
        self.os.servers.rebuild(self.server.id, FLAGS.image)

        # Must wait for the rebuild to start, or self.os.servers.get
        # throws an exception
        time.sleep(4)

        # Legal states...
        states = utils.StatusTracker('active', 'build', 'active')

        # Wait for server to transition to next state and make sure it
        # went to the correct one
        dtutil.assert_is(True,
                         states.waitForState(self.os.servers.get,
                                             'status', self.server))

        # Verify that rebuild acted correctly
        created_server = self.os.servers.get(self.server.id)
        img = self.os.images.get(FLAGS.image)

        dtutil.assert_equal(img.id, created_server.imageId)
Ejemplo n.º 13
0
    def test_get(self):
        """Test that we can get the details of a given image."""

        # Let's try to get our test image
        img = self.os.images.get(self._image_id)

        # Check that all the details match
        dtutil.assert_equal(img.id, self._image_id)
        dtutil.assert_equal(img.name, self._image_name)
        dtutil.assert_equal(img.status, 'ACTIVE')
Ejemplo n.º 14
0
    def test_list(self):
        """Test that flavors can be listed."""

        # See if we can retrieve the list of flavors
        flavors = self.os.flavors.list()

        # Do we have a list?
        dtutil.assert_not_equal(len(flavors), 0)

        # Let's see if some of our base-line flavors are present
        foundflav = 0
        for flav in flavors:
            if flav.name in self.recognized_flavors:
                exemplar = self.recognized_flavors[flav.name]
                dtutil.assert_equal(flav.id, exemplar['id'])
                dtutil.assert_equal(flav.ram, exemplar['ram'])
                dtutil.assert_equal(flav.disk, exemplar['disk'])
                foundflav += 1

        # Make sure we found our flavors
        dtutil.assert_equal(len(self.recognized_flavors), foundflav)
Ejemplo n.º 15
0
    def test_create_and_delete(self):
        """Test that an image can be created and deleted."""

        name = self.randName(prefix="create_delete_image_")

        # Create a new image
        new_meta = self.create_glance_image(file_name=FLAGS.test_image,
                                          image_name=name)

        # Verify it exists and the values are correct
        img = self.os.images.get(new_meta['id'])
        dtutil.assert_equal(img.id, new_meta['id'])
        dtutil.assert_equal(img.name, new_meta['name'])
        dtutil.assert_equal(img.status, 'ACTIVE')

        # Delete the image
        self.glance_connection.delete_image(new_meta['id'])

        # Verify it cannot be retrieved
        dtutil.assert_raises(novaclient.exceptions.NotFound,
                             self.os.images.get, new_meta['id'])
Ejemplo n.º 16
0
    def test_backup_schedules(self):
        """Test the backup schedules.

        This is not yet implemented in Nova.
        """
        try:
            # Create a server and a schedule
            self.server.backup_schedule.create(
                enabled=True,
                weekly=novaclient.BACKUP_WEEKLY_SUNDAY,
                daily=novaclient.BACKUP_DAILY_DISABLED)

            # Get the schedule and verify it is correct
            new_sched = self.server.backup_schedule.get()
            dtutil.assert_equal(new_sched.enabled, True)
            dtutil.assert_equal(new_sched.weekly,
                                weekly=novaclient.BACKUP_WEEKLY_SUNDAY)
            dtutil.assert_equal(new_sched.daily,
                                novaclient.BACKUP_DAILY_DISABLED)
        except novaclient.exceptions.HTTPNotImplemented as ex:
            raise AssertionError("backup schedules are not implemented")
        finally:
            self.server.delete()