Exemplo n.º 1
0
    def test_bad_resize_vol_data(self):
        def _check_instance_status():
            inst = self.dbaas.instances.get(self.instance)
            if inst.status == "ACTIVE":
                return True
            else:
                return False

        poll_until(_check_instance_status)
        data = "bad data"
        try:
            self.dbaas.instances.resize_volume(self.instance.id, data)
        except Exception as e:
            resp, body = self.dbaas.client.last_response
            httpCode = resp.status
            assert_equal(
                httpCode, 400,
                "Resize instance failed with code %s, exception %s" %
                (httpCode, e))
            data = "u'bad data'"
            assert_equal(
                e.message, "Validation error: "
                "resize['volume']['size'] %s "
                "is not valid under any of the given schemas; "
                "%s is not of type 'integer'; "
                "%s does not match '[0-9]+'" % (data, data, data))
    def test_bad_change_user_password(self):
        password = ""
        users = [{"name": password}]

        def _check_instance_status():
            inst = self.dbaas.instances.get(self.instance)
            if inst.status == "ACTIVE":
                return True
            else:
                return False

        poll_until(_check_instance_status)
        try:
            self.dbaas.users.change_passwords(self.instance, users)
        except Exception as e:
            resp, body = self.dbaas.client.last_response
            httpCode = resp.status
            assert_equal(httpCode, 400,
                         "Change usr/passwd failed with code %s, exception %s"
                         % (httpCode, e))
            if not isinstance(self.dbaas.client,
                              troveclient.xml.TroveXmlClient):
                password = "******"
                assert_equal(e.message,
                             "Validation error: "
                             "users[0] 'password' is a required property; "
                             "users[0]['name'] %s is too short; "
                             "users[0]['name'] %s does not match "
                             "'^.*[0-9a-zA-Z]+.*$'" %
                             (password, password))
Exemplo n.º 3
0
    def test_backup_delete(self):
        """test delete"""

        # Test to make sure that user in other tenant is not able
        # to DELETE this backup
        reqs = Requirements(is_admin=False)
        other_user = CONFIG.users.find_user(
            reqs,
            black_list=[instance_info.user.auth_user])
        other_client = create_dbaas_client(other_user)
        assert_raises(exceptions.NotFound, other_client.backups.delete,
                      backup_info.id)

        instance_info.dbaas.backups.delete(backup_info.id)
        assert_equal(202, instance_info.dbaas.last_http_code)

        def backup_is_gone():
            result = instance_info.dbaas.instances.backups(instance_info.id)
            if len(result) == 0:
                return True
            else:
                return False
        poll_until(backup_is_gone)
        assert_raises(exceptions.NotFound, instance_info.dbaas.backups.get,
                      backup_info.id)
Exemplo n.º 4
0
    def test_bad_change_user_password(self):
        password = ""
        users = [{"name": password}]

        def _check_instance_status():
            inst = self.dbaas.instances.get(self.instance)
            if inst.status == "ACTIVE":
                return True
            else:
                return False

        poll_until(_check_instance_status)
        try:
            self.dbaas.users.change_passwords(self.instance, users)
        except Exception as e:
            resp, body = self.dbaas.client.last_response
            httpCode = resp.status
            assert_equal(
                httpCode, 400,
                "Change usr/passwd failed with code %s, exception %s" %
                (httpCode, e))
            if not isinstance(self.dbaas.client,
                              troveclient.xml.TroveXmlClient):
                password = "******"
                assert_equal(
                    e.message, "Validation error: "
                    "users[0] 'password' is a required property; "
                    "users[0]['name'] %s is too short; "
                    "users[0]['name'] %s does not match "
                    "'^.*[0-9a-zA-Z]+.*$'" % (password, password))
    def test_bad_resize_vol_data(self):
        def _check_instance_status():
            inst = self.dbaas.instances.get(self.instance)
            if inst.status == "ACTIVE":
                return True
            else:
                return False

        poll_until(_check_instance_status)
        data = "bad data"
        try:
            self.dbaas.instances.resize_volume(self.instance.id, data)
        except Exception as e:
            resp, body = self.dbaas.client.last_response
            httpCode = resp.status
            assert_equal(httpCode, 400,
                         "Resize instance failed with code %s, exception %s"
                         % (httpCode, e))
            data = "u'bad data'"
            assert_equal(e.message,
                         "Validation error: "
                         "resize['volume']['size'] %s "
                         "is not valid under any of the given schemas; "
                         "%s is not of type 'integer'; "
                         "%s does not match '[0-9]+'" %
                         (data, data, data))
Exemplo n.º 6
0
    def test_backup_delete(self):
        """test delete"""

        # Test to make sure that user in other tenant is not able
        # to DELETE this backup
        reqs = Requirements(is_admin=False)
        other_user = CONFIG.users.find_user(
            reqs,
            black_list=[instance_info.user.auth_user])
        other_client = create_dbaas_client(other_user)
        assert_raises(exceptions.NotFound, other_client.backups.delete,
                      backup_info.id)

        instance_info.dbaas.backups.delete(backup_info.id)
        assert_equal(202, instance_info.dbaas.last_http_code)

        def backup_is_gone():
            result = instance_info.dbaas.instances.backups(instance_info.id)
            if len(result) == 0:
                return True
            else:
                return False
        poll_until(backup_is_gone)
        assert_raises(exceptions.NotFound, instance_info.dbaas.backups.get,
                      backup_info.id)
Exemplo n.º 7
0
 def test_create_backup_with_instance_not_active(self):
     name = "spare_instance"
     flavor = 2
     self.databases.append({"name": "db2"})
     self.users.append({"name": "lite", "password": "******",
                        "databases": [{"name": "db2"}]})
     volume = {'size': 2}
     self.xtra_instance = instance_info.dbaas.instances.create(
         name,
         flavor,
         volume,
         self.databases,
         self.users)
     assert_equal(200, instance_info.dbaas.last_http_code)
     # immediately create the backup while instance is still in "BUILD"
     try:
         self.xtra_backup = self._create_backup(
             BACKUP_NAME, BACKUP_DESC, inst_id=self.xtra_instance.id)
         assert_true(False, "Expected 422 from create backup")
     except exceptions.UnprocessableEntity:
         assert_equal(422, instance_info.dbaas.last_http_code)
     assert_equal(422, instance_info.dbaas.last_http_code)
     # make sure the instance status goes back to "ACTIVE"
     poll_until(lambda: self._verify_instance_status(self.xtra_instance.id,
                                                     "ACTIVE"),
                time_out=120, sleep_time=2)
     # Now that it's active, create the backup
     self.xtra_backup = self._create_backup(BACKUP_NAME, BACKUP_DESC)
     assert_equal(202, instance_info.dbaas.last_http_code)
     poll_until(lambda: self._verify_backup_status(self.xtra_backup.id,
                                                   'COMPLETED'),
                time_out=120, sleep_time=2)
Exemplo n.º 8
0
def restart_compute_service(extra_args=None):
    extra_args = extra_args or []
    test_config.compute_service.restart(extra_args=extra_args)
    # Be absolutely certain the compute manager is ready before passing control
    # back to caller.
    poll_until(lambda: hosts_up('compute'), sleep_time=1, time_out=60)
    wait_for_compute_service()
Exemplo n.º 9
0
 def wait_for_resize(self):
     def is_finished_resizing():
         instance = self.instance
         if instance.status == "RESIZE":
             return False
         assert_equal("ACTIVE", instance.status)
         return True
     testsutil.poll_until(is_finished_resizing, time_out=TIME_OUT_TIME)
Exemplo n.º 10
0
def restart_compute_service(extra_args=None):
    extra_args = extra_args or []
    test_config.compute_service.restart(extra_args=extra_args)
    # Be absolutely certain the compute manager is ready before passing control
    # back to caller.
    poll_until(lambda: hosts_up('compute'),
                     sleep_time=1, time_out=60)
    wait_for_compute_service()
Exemplo n.º 11
0
 def wait_for_resize(self):
     def is_finished_resizing():
         instance = self.instance
         if instance.status == "RESIZE":
             return False
         assert_equal("ACTIVE", instance.status)
         return True
     poll_until(is_finished_resizing, time_out=TIME_OUT_TIME)
Exemplo n.º 12
0
 def wait_for_broken_connection(self):
     """Wait until our connection breaks."""
     if not USE_IP:
         return
     if not hasattr(self, "connection"):
         return
     poll_until(self.connection.is_connected,
                lambda connected: not connected,
                time_out=TIME_OUT_TIME)
Exemplo n.º 13
0
 def wait_for_broken_connection(self):
     """Wait until our connection breaks."""
     if not USE_IP:
         return
     if not hasattr(self, "connection"):
         return
     testsutil.poll_until(self.connection.is_connected,
                          lambda connected: not connected,
                          time_out=TIME_OUT_TIME)
Exemplo n.º 14
0
def wait_for_compute_service():
    pid = test_config.compute_service.find_proc_id()
    line = "Creating Consumer connection for Service compute from (pid=%d)" % \
           pid
    try:
        poll_until(lambda: check_logs_for_message(line),
                         sleep_time=1, time_out=60)
    except exception.PollTimeOut:
        raise RuntimeError("Could not find the line %s in the logs." % line)
Exemplo n.º 15
0
    def wait_for_successful_restart(self):
        """Wait until status becomes running."""
        def is_finished_rebooting():
            instance = self.instance
            if instance.status == "REBOOT":
                return False
            assert_equal("ACTIVE", instance.status)
            return True

        testsutil.poll_until(is_finished_rebooting, time_out=TIME_OUT_TIME)
Exemplo n.º 16
0
 def test_instance_action_right_after_backup_create(self):
     """test any instance action while backup is running"""
     backup = self._create_backup("modify_during_create",
                                  "modify instance while creating backup")
     assert_equal(202, instance_info.dbaas.last_http_code)
     # Dont wait for backup to complete, try to delete it
     assert_unprocessable(instance_info.dbaas.instances.resize_instance,
                          instance_info.id, 1)
     poll_until(lambda: self._verify_backup_status(backup.id, 'COMPLETED'),
                time_out=120, sleep_time=2)
Exemplo n.º 17
0
    def wait_for_successful_restart(self):
        """Wait until status becomes running."""
        def is_finished_rebooting():
            instance = self.instance
            if instance.status == "REBOOT":
                return False
            assert_equal("ACTIVE", instance.status)
            return True

        poll_until(is_finished_rebooting, time_out=TIME_OUT_TIME)
Exemplo n.º 18
0
def wait_for_compute_service():
    pid = test_config.compute_service.find_proc_id()
    line = "Creating Consumer connection for Service compute from (pid=%d)" % \
           pid
    try:
        poll_until(lambda: check_logs_for_message(line),
                   sleep_time=1,
                   time_out=60)
    except exception.PollTimeOut:
        raise RuntimeError("Could not find the line %s in the logs." % line)
Exemplo n.º 19
0
    def update_and_wait_to_finish(self):
        instance_info.dbaas_admin.management.update(instance_info.id)

        def finished():
            current_version = self.get_version()
            if current_version == self.next_version:
                return True
            # The only valid thing for it to be aside from next_version is
            # old version.
            assert_equal(current_version, self.old_version)
        poll_until(finished, sleep_time=1, time_out=3 * 60)
Exemplo n.º 20
0
    def update_and_wait_to_finish(self):
        instance_info.dbaas_admin.management.update(instance_info.id)

        def finished():
            current_version = self.get_version()
            if current_version == self.next_version:
                return True
            # The only valid thing for it to be aside from next_version is
            # old version.
            assert_equal(current_version, self.old_version)
        testsutil.poll_until(finished, sleep_time=1, time_out=3 * 60)
Exemplo n.º 21
0
 def test_clean_up_backups(self):
     backup_list = instance_info.dbaas.backups.list()
     for backup in backup_list:
         print("Cleanup backup: %r and status: %r" % (backup.id, backup.status))
         if backup.status == 'COMPLETED':
             try:
                 self._delete_backup(backup.id)
                 assert_equal(202, instance_info.dbaas.last_http_code)
                 poll_until(lambda: self._backup_is_gone(backup.id))
             except exceptions.NotFound:
                 assert_equal(404, instance_info.dbaas.last_http_code)
Exemplo n.º 22
0
    def test_backup_created(self):
        # This version just checks the REST API status.
        def result_is_active():
            backup = instance_info.dbaas.backups.get(backup_info.id)
            if backup.status == "COMPLETED":
                return True
            else:
                assert_not_equal("FAILED", backup.status)
                return False

        poll_until(result_is_active)
Exemplo n.º 23
0
    def test_backup_created(self):
        # This version just checks the REST API status.
        def result_is_active():
            backup = instance_info.dbaas.backups.get(backup_info.id)
            if backup.status == "COMPLETED":
                return True
            else:
                assert_not_equal("FAILED", backup.status)
                return False

        poll_until(result_is_active)
Exemplo n.º 24
0
 def test_delete_deleted_backup(self):
     backup = self._create_backup("del_backup", "delete a deleted backup")
     assert_equal(202, instance_info.dbaas.last_http_code)
     poll_until(lambda: self._verify_backup_status(backup.id, 'COMPLETED'),
                time_out=120, sleep_time=1)
     self._delete_backup(backup.id)
     poll_until(lambda: self._backup_is_gone(backup.id))
     try:
         self._delete_backup(backup.id)
         assert_true(False, "Expected 404 from delete backup")
     except exceptions.NotFound:
         assert_equal(404, instance_info.dbaas.last_http_code)
Exemplo n.º 25
0
    def test_volume_resize_success(self):
        def check_resize_status():
            instance = instance_info.dbaas.instances.get(instance_info.id)
            if instance.status == "ACTIVE":
                return True
            elif instance.status == "RESIZE":
                return False
            else:
                fail("Status should not be %s" % instance.status)

        testsutil.poll_until(check_resize_status, sleep_time=2, time_out=300)
        instance = instance_info.dbaas.instances.get(instance_info.id)
        assert_equal(instance.volume['size'], self.new_volume_size)
Exemplo n.º 26
0
    def wait_for_failure_status(self):
        """Wait until status becomes running."""
        def is_finished_rebooting():
            instance = self.instance
            if instance.status == "REBOOT" or instance.status == "ACTIVE":
                return False
            # The reason we check for BLOCKED as well as SHUTDOWN is because
            # Upstart might try to bring mysql back up after the borked
            # connection and the guest status can be either
            assert_true(instance.status in ("SHUTDOWN", "BLOCKED"))
            return True

        poll_until(is_finished_rebooting, time_out=TIME_OUT_TIME)
Exemplo n.º 27
0
    def wait_for_failure_status(self):
        """Wait until status becomes running."""
        def is_finished_rebooting():
            instance = self.instance
            if instance.status == "REBOOT" or instance.status == "ACTIVE":
                return False
            # The reason we check for BLOCKED as well as SHUTDOWN is because
            # Upstart might try to bring mysql back up after the borked
            # connection and the guest status can be either
            assert_true(instance.status in ("SHUTDOWN", "BLOCKED"))
            return True

        testsutil.poll_until(is_finished_rebooting, time_out=TIME_OUT_TIME)
Exemplo n.º 28
0
    def test_instance_resize_to_ephemeral_in_volume_support_should_fail(self):
        flavor_name = CONFIG.values.get('instance_bigger_eph_flavor_name',
                                        'eph.rd-smaller')
        flavors = self.dbaas.find_flavors_by_name(flavor_name)

        def is_active():
            return self.instance.status == 'ACTIVE'
        poll_until(is_active, time_out=TIME_OUT_TIME)
        assert_equal(self.instance.status, 'ACTIVE')

        old_flavor_href = self.get_flavor_href(
            flavor_id=self.expected_old_flavor_id)
        assert_raises(HTTPNotImplemented, self.dbaas.instances.resize_instance,
                      self.instance_id, flavors[0].id)
Exemplo n.º 29
0
    def create_user(self):
        """Create a MySQL user we can use for this test."""

        users = [{"name": MYSQL_USERNAME, "password": MYSQL_PASSWORD,
                  "databases": [{"name": MYSQL_USERNAME}]}]
        self.dbaas.users.create(instance_info.id, users)

        def has_user():
            users = self.dbaas.users.list(instance_info.id)
            return any([user.name == MYSQL_USERNAME for user in users])

        poll_until(has_user, time_out=30)
        if not FAKE_MODE:
            time.sleep(5)
Exemplo n.º 30
0
    def test_instance_resize_to_ephemeral_in_volume_support_should_fail(self):
        flavor_name = CONFIG.values.get('instance_bigger_eph_flavor_name',
                                        'eph.rd-smaller')
        flavors = self.dbaas.find_flavors_by_name(flavor_name)

        def is_active():
            return self.instance.status == 'ACTIVE'
        testsutil.poll_until(is_active, time_out=TIME_OUT_TIME)
        assert_equal(self.instance.status, 'ACTIVE')

        self.get_flavor_href(
            flavor_id=self.expected_old_flavor_id)
        assert_raises(HTTPNotImplemented, self.dbaas.instances.resize_instance,
                      self.instance_id, flavors[0].id)
Exemplo n.º 31
0
 def test_create_backup(self):
     databases = []
     databases.append({"name": BACKUP_DB_NAME, "charset": "latin2",
                       "collate": "latin2_general_ci"})
     instance_info.dbaas.databases.create(instance_info.id, databases)
     assert_equal(202, instance_info.dbaas.last_http_code)
     backup = self._create_backup(BACKUP_NAME, BACKUP_DESC,
                                  instance_info.id)
     self.backup_id = backup.id
     assert_equal(backup.name, BACKUP_NAME)
     assert_equal(backup.description, BACKUP_DESC)
     assert_equal(backup.instance_id, instance_info.id)
     assert_equal(backup.status, 'NEW')
     assert_is_not_none(backup.id, 'backup.id does not exist')
     assert_is_not_none(backup.created, 'backup.created does not exist')
     assert_is_not_none(backup.updated, 'backup.updated does not exist')
     instance = instance_info.dbaas.instances.get(instance_info.id)
     assert_true(instance.status in ('ACTIVE', 'BACKUP'))
     # Get Backup status by backup id during and after backup creation
     poll_until(lambda: self._verify_instance_status(instance.id,
                                                     'BACKUP'),
                time_out=120, sleep_time=2)
     poll_until(lambda: self._verify_backup_status(backup.id, 'BUILDING'),
                time_out=120, sleep_time=2)
     poll_until(lambda: self._verify_backup_status(backup.id, 'COMPLETED'),
                time_out=120, sleep_time=2)
     poll_until(lambda: self._verify_instance_status(instance.id,
                                                     'ACTIVE'),
                time_out=120, sleep_time=2)
Exemplo n.º 32
0
    def test_volume_resize_success(self):

        def check_resize_status():
            instance = instance_info.dbaas.instances.get(instance_info.id)
            if instance.status == "ACTIVE":
                return True
            elif instance.status == "RESIZE":
                return False
            else:
                fail("Status should not be %s" % instance.status)

        testsutil.poll_until(check_resize_status, sleep_time=2, time_out=300)
        instance = instance_info.dbaas.instances.get(instance_info.id)
        assert_equal(instance.volume['size'], self.new_volume_size)
Exemplo n.º 33
0
    def create_user(self):
        """Create a MySQL user we can use for this test."""

        users = [{"name": MYSQL_USERNAME, "password": MYSQL_PASSWORD,
                  "databases": [{"name": MYSQL_USERNAME}]}]
        self.dbaas.users.create(instance_info.id, users)

        def has_user():
            users = self.dbaas.users.list(instance_info.id)
            return any([user.name == MYSQL_USERNAME for user in users])

        testsutil.poll_until(has_user, time_out=30)
        if not FAKE_MODE:
            time.sleep(5)
Exemplo n.º 34
0
    def test_backup_delete(self):
        """test delete"""
        instance_info.dbaas.backups.delete(backup_info.id)
        assert_equal(202, instance_info.dbaas.last_http_code)

        def backup_is_gone():
            result = instance_info.dbaas.instances.backups(instance_info.id)
            if len(result) == 0:
                return True
            else:
                return False
        poll_until(backup_is_gone)
        assert_raises(exceptions.NotFound, instance_info.dbaas.backups.get,
                      backup_info.id)
Exemplo n.º 35
0
 def test_restore_backup_account_not_owned(self):
     if test_config.auth_strategy == "fake":
         raise SkipTest("Skipping restore tests for fake mode.")
     backup = self._create_backup("rest_not_owned_backup",
                                  "restoring a backup of a different user")
     assert_equal(202, instance_info.dbaas.last_http_code)
     poll_until(lambda: self._verify_backup_status(backup.id, 'COMPLETED'),
                time_out=120, sleep_time=2)
     try:
         self._create_restore(self.spare_client, backup.id)
         assert_true(False, "Expected 404 from create restore")
     except exceptions.ClientException:
         assert_equal(404, self.spare_client.last_http_code)
     instance_info.dbaas.backups.delete(backup.id)
     poll_until(lambda: self._backup_is_gone(backup_id=backup.id))
Exemplo n.º 36
0
 def test_delete_while_backing_up(self):
     backup = self._create_backup("delete_as_backup",
                                  "delete backup while backing up")
     assert_equal(202, instance_info.dbaas.last_http_code)
     # Dont wait for backup to complete, try to delete it
     try:
         self._delete_backup(backup.id)
         assert_true(False, "Expected 422 from delete backup")
     except:
         assert_equal(422, instance_info.dbaas.last_http_code)
     poll_until(lambda: self._verify_backup_status(backup.id, 'COMPLETED'),
                time_out=120, sleep_time=1)
     # DCF WHy is this delete different than the one above that uses the helper function?
     instance_info.dbaas.backups.delete(backup.id)
     poll_until(lambda: self._backup_is_gone(backup_id=backup.id))
Exemplo n.º 37
0
 def test_restore_deleted_backup(self):
     if test_config.auth_strategy == "fake":
         raise SkipTest("Skipping restore tests for fake mode.")
     backup = self._create_backup("rest_del_backup",
                                  "restoring a deleted backup")
     assert_equal(202, instance_info.dbaas.last_http_code)
     poll_until(lambda: self._verify_backup_status(backup.id, 'COMPLETED'),
                time_out=120, sleep_time=2)
     self._delete_backup(backup.id)
     poll_until(self._backup_is_gone(backup.id))
     try:
         self._create_restore(instance_info.dbaas, backup.id)
         assert_true(False, "Expected 404 from create restore")
     except exceptions.ClientException:
         assert_equal(404, instance_info.dbaas.last_http_code)
Exemplo n.º 38
0
 def test_delete_restored_instance(self):
     if test_config.auth_strategy == "fake":
         raise SkipTest("Skipping delete restored instance for fake mode.")
         # Create a backup to list after instance is deleted
     backup = self._create_backup(self.restored_name,
                                  self.restored_desc,
                                  inst_id=self.restore_id)
     assert_equal(202, instance_info.dbaas.last_http_code)
     poll_until(lambda: self._verify_backup_status(backup.id, 'COMPLETED'),
                time_out=120, sleep_time=2)
     self.deleted_backup_id = backup.id
     instance_info.dbaas.instances.delete(self.restore_id)
     assert_equal(202, instance_info.dbaas.last_http_code)
     poll_until(lambda: self._instance_is_gone(self.restore_id))
     assert_raises(exceptions.NotFound, instance_info.dbaas.instances.get,
                   self.restore_id)
Exemplo n.º 39
0
 def test_bad_resize_vol_data(self):
     def _check_instance_status():
         inst = self.dbaas.instances.get(self.instance)
         if inst.status == "ACTIVE":
             return True
         else:
             return False
     poll_until(_check_instance_status)
     try:
         self.dbaas.instances.resize_volume(self.instance.id, "bad data")
     except Exception as e:
         resp, body = self.dbaas.client.last_response
         httpCode = resp.status
         assert_true(httpCode == 400,
                     "Resize instance failed with code %s, exception %s"
                     % (httpCode, e))
Exemplo n.º 40
0
    def test_delete_restored_instance(self):
        """test delete restored instance"""
        if test_config.auth_strategy == "fake":
            raise SkipTest("Skipping delete restored instance for fake mode.")
        instance_info.dbaas.instances.delete(restore_instance_id)
        assert_equal(202, instance_info.dbaas.last_http_code)

        def instance_is_gone():
            try:
                instance_info.dbaas.instances.get(restore_instance_id)
                return False
            except exceptions.NotFound:
                return True

        poll_until(instance_is_gone)
        assert_raises(exceptions.NotFound, instance_info.dbaas.instances.get,
                      restore_instance_id)
Exemplo n.º 41
0
    def test_delete_restored_instance(self):
        """test delete restored instance"""
        if test_config.auth_strategy == "fake":
            raise SkipTest("Skipping delete restored instance for fake mode.")
        instance_info.dbaas.instances.delete(restore_instance_id)
        assert_equal(202, instance_info.dbaas.last_http_code)

        def instance_is_gone():
            try:
                instance_info.dbaas.instances.get(restore_instance_id)
                return False
            except exceptions.NotFound:
                return True

        poll_until(instance_is_gone)
        assert_raises(exceptions.NotFound, instance_info.dbaas.instances.get,
                      restore_instance_id)
Exemplo n.º 42
0
 def setUp(self):
     self.user = test_config.users.find_user(Requirements(is_admin=True))
     self.client = create_dbaas_client(self.user)
     self.name = 'test_SERVER_ERROR'
     # Create an instance with a broken compute instance.
     volume = None
     if CONFIG.trove_volume_support:
         volume = {'size': 1}
     self.response = self.client.instances.create(
         self.name, instance_info.dbaas_flavor_href, volume, [])
     poll_until(lambda: self.client.instances.get(self.response.id),
                lambda instance: instance.status == 'ERROR',
                time_out=10)
     self.instance = self.client.instances.get(self.response.id)
     print("Status: %s" % self.instance.status)
     msg = "Instance did not drop to error after server prov failure."
     assert_equal(self.instance.status, "ERROR", msg)
Exemplo n.º 43
0
 def test_restore_backup(self):
     if test_config.auth_strategy == "fake":
         # We should create restore logic in fake guest agent to not skip
         raise SkipTest("Skipping restore tests for fake mode.")
     restore_resp = self._create_restore(instance_info.dbaas,
                                         self.backup_id)
     assert_equal(200, instance_info.dbaas.last_http_code)
     assert_equal("BUILD", restore_resp.status)
     assert_is_not_none(restore_resp.id, 'restored inst_id does not exist')
     self.restore_id = restore_resp.id
     poll_until(self._result_is_active)
     restored_inst = instance_info.dbaas.instances.get(self.restore_id)
     assert_is_not_none(restored_inst, 'restored instance does not exist')
     assert_equal(restored_inst.name, BACKUP_NAME + "_restore")
     assert_equal(restored_inst.status, 'ACTIVE')
     assert_is_not_none(restored_inst.id, 'restored inst_id does not exist')
     self._verify_databases(BACKUP_DB_NAME)
Exemplo n.º 44
0
 def test_delete_negative_instance(self):
     try:
         self._delete_backup(self.xtra_backup.id)
         assert_equal(202, instance_info.dbaas.last_http_code)
         poll_until(lambda: self._backup_is_gone(self.xtra_backup.id))
     except exceptions.NotFound:
         assert_equal(404, instance_info.dbaas.last_http_code)
     try:
         instance_info.dbaas.instances.delete(self.xtra_instance.id)
         assert_equal(202, instance_info.dbaas.last_http_code)
         poll_until(lambda: self._instance_is_gone(self.xtra_instance.id))
     except exceptions.NotFound:
         assert_equal(404, instance_info.dbaas.last_http_code)
     finally:
         assert_raises(exceptions.NotFound,
                       instance_info.dbaas.instances.get,
                       self.xtra_instance.id)
Exemplo n.º 45
0
    def test_instance_restored(self):
        if test_config.auth_strategy == "fake":
            raise SkipTest("Skipping restore tests for fake mode.")

        # This version just checks the REST API status.
        def result_is_active():
            instance = instance_info.dbaas.instances.get(restore_instance_id)
            if instance.status == "ACTIVE":
                return True
            else:
                # If its not ACTIVE, anything but BUILD must be
                # an error.
                assert_equal("BUILD", instance.status)
                if instance_info.volume is not None:
                    assert_equal(instance.volume.get('used', None), None)
                return False

        poll_until(result_is_active)
Exemplo n.º 46
0
    def test_bad_resize_instance_data(self):
        def _check_instance_status():
            inst = self.dbaas.instances.get(self.instance)
            if inst.status == "ACTIVE":
                return True
            else:
                return False

        poll_until(_check_instance_status)
        try:
            self.dbaas.instances.resize_instance(self.instance.id, "bad data")
        except Exception as e:
            resp, body = self.dbaas.client.last_response
            httpCode = resp.status
            assert_equal(
                httpCode, 400,
                "Resize instance failed with code %s, exception %s" %
                (httpCode, e))
Exemplo n.º 47
0
    def test_resize_down(self):
        expected_dbaas_flavor = self.expected_dbaas_flavor

        def is_active():
            return self.instance.status == 'ACTIVE'
        testsutil.poll_until(is_active, time_out=TIME_OUT_TIME)
        assert_equal(self.instance.status, 'ACTIVE')

        old_flavor_href = self.get_flavor_href(
            flavor_id=self.expected_old_flavor_id)

        self.dbaas.instances.resize_instance(self.instance_id, old_flavor_href)
        assert_equal(202, self.dbaas.last_http_code)
        self.old_dbaas_flavor = instance_info.dbaas_flavor
        instance_info.dbaas_flavor = expected_dbaas_flavor
        self.wait_for_resize()
        assert_equal(str(self.instance.flavor['id']),
                     str(self.expected_old_flavor_id))
Exemplo n.º 48
0
    def test_resize_down(self):
        expected_dbaas_flavor = self.expected_dbaas_flavor

        def is_active():
            return self.instance.status == 'ACTIVE'
        poll_until(is_active, time_out=TIME_OUT_TIME)
        assert_equal(self.instance.status, 'ACTIVE')

        old_flavor_href = self.get_flavor_href(
            flavor_id=self.expected_old_flavor_id)

        self.dbaas.instances.resize_instance(self.instance_id, old_flavor_href)
        assert_equal(202, self.dbaas.last_http_code)
        self.old_dbaas_flavor = instance_info.dbaas_flavor
        instance_info.dbaas_flavor = expected_dbaas_flavor
        self.wait_for_resize()
        assert_equal(str(self.instance.flavor['id']),
                     str(self.expected_old_flavor_id))
Exemplo n.º 49
0
    def test_instance_restored(self):
        if test_config.auth_strategy == "fake":
            raise SkipTest("Skipping restore tests for fake mode.")

        # This version just checks the REST API status.
        def result_is_active():
            instance = instance_info.dbaas.instances.get(restore_instance_id)
            if instance.status == "ACTIVE":
                return True
            else:
                # If its not ACTIVE, anything but BUILD must be
                # an error.
                assert_equal("BUILD", instance.status)
                if instance_info.volume is not None:
                    assert_equal(instance.volume.get('used', None), None)
                return False

        poll_until(result_is_active)
Exemplo n.º 50
0
 def set_up(self):
     """Create client for mgmt instance test (2)."""
     if not CONFIG.fake_mode:
         raise SkipTest("This test only works in fake mode.")
     self.client = create_client(is_admin=True)
     self.mgmt = self.client.management
     # Fake nova will fail a server ending with 'test_SERVER_ERROR'."
     # Fake volume will fail if the size is 13.
     # TODO(tim.simpson): This would be a lot nicer looking if we used a
     #                    traditional mock framework.
     body = None
     if CONFIG.trove_volume_support:
         body = {'size': 13}
     response = self.client.instances.create(
         'test_SERVER_ERROR', instance_info.dbaas_flavor_href, body, [])
     poll_until(lambda: self.client.instances.get(response.id),
                lambda instance: instance.status == 'ERROR',
                time_out=10)
     self.id = response.id
Exemplo n.º 51
0
    def test_bad_grant_user_access(self):
        dbs = []

        def _check_instance_status():
            inst = self.dbaas.instances.get(self.instance)
            if inst.status == "ACTIVE":
                return True
            else:
                return False

        poll_until(_check_instance_status)
        try:
            self.dbaas.users.grant(self.instance, self.user, dbs)
        except Exception as e:
            resp, body = self.dbaas.client.last_response
            httpCode = resp.status
            assert_equal(
                httpCode, 400,
                "Grant user access failed with code %s, exception "
                "%s" % (httpCode, e))
Exemplo n.º 52
0
    def test_bad_revoke_user_access(self):
        db = ""

        def _check_instance_status():
            inst = self.dbaas.instances.get(self.instance)
            if inst.status == "ACTIVE":
                return True
            else:
                return False

        poll_until(_check_instance_status)
        try:
            self.dbaas.users.revoke(self.instance, self.user, db)
        except Exception as e:
            resp, body = self.dbaas.client.last_response
            httpCode = resp.status
            assert_equal(
                httpCode, 404,
                "Revoke user access failed w/code %s, exception %s" %
                (httpCode, e))
            assert_equal(e.message, "The resource could not be found.")
Exemplo n.º 53
0
 def wait_for_instance_status(self, instance_id, status="ACTIVE"):
     poll_until(lambda: self.dbaas.instances.get(instance_id),
                lambda instance: instance.status == status,
                time_out=10)
Exemplo n.º 54
0
 def wait_for_instance_task_status(self, instance_id, description):
     poll_until(lambda: self.dbaas.management.show(instance_id),
                lambda instance: instance.task_description == description,
                time_out=10)
Exemplo n.º 55
0
 def _wait_for_active(self):
     poll_until(lambda: self.client.instances.get(self.id),
                lambda instance: instance.status == "ACTIVE",
                time_out=(60 * 8))
Exemplo n.º 56
0
 def resize_volume_in_shutdown_state(self):
     self.client.instances.resize_volume(self.id, 2)
     poll_until(lambda: self.client.instances.get(self.id),
                lambda instance: instance.volume['size'] == 2,
                time_out=(60 * 8))