Beispiel #1
0
 def _assert_cluster_values(self,
                            cluster,
                            expected_task_name,
                            check_locality=True):
     with TypeCheck('Cluster', cluster) as check:
         check.has_field("id", six.string_types)
         check.has_field("name", six.string_types)
         check.has_field("datastore", dict)
         check.has_field("instances", list)
         check.has_field("links", list)
         check.has_field("created", six.text_type)
         check.has_field("updated", six.text_type)
         if check_locality:
             check.has_field("locality", six.text_type)
         if self.active_config_group_id:
             check.has_field("configuration", six.text_type)
         for instance in cluster.instances:
             isinstance(instance, dict)
             self.assert_is_not_none(instance['id'])
             self.assert_is_not_none(instance['links'])
             self.assert_is_not_none(instance['name'])
     self.assert_equal(expected_task_name, cluster.task['name'],
                       'Unexpected cluster task name')
     if check_locality:
         self.assert_equal(self.locality, cluster.locality,
                           "Unexpected cluster locality")
Beispiel #2
0
    def assert_create_group(self, name, description, values,
                            expected_http_code):
        json_def = json.dumps(values)
        client = self.auth_client
        result = client.configurations.create(
            name,
            json_def,
            description,
            datastore=self.instance_info.dbaas_datastore,
            datastore_version=self.instance_info.dbaas_datastore_version)
        self.assert_client_code(client, expected_http_code)

        with TypeCheck('Configuration', result) as configuration:
            configuration.has_field('name', basestring)
            configuration.has_field('description', basestring)
            configuration.has_field('values', dict)
            configuration.has_field('datastore_name', basestring)
            configuration.has_field('datastore_version_id', unicode)
            configuration.has_field('datastore_version_name', basestring)

            self.assert_equal(name, result.name)
            self.assert_equal(description, result.description)
            self.assert_equal(values, result.values)

        return result.id
Beispiel #3
0
 def test_create_security_group_rule(self):
     if len(self.testSecurityGroup.rules) == 0:
         self.testSecurityGroupRule = \
             dbaas.security_group_rules.create(
                 group_id=self.testSecurityGroup.id,
                 protocol="tcp",
                 from_port=3306,
                 to_port=3306,
                 cidr="0.0.0.0/0")
         assert_is_not_none(self.testSecurityGroupRule)
         with TypeCheck('SecurityGroupRule',
                        self.testSecurityGroupRule) as secGrpRule:
             secGrpRule.has_field('id', basestring)
             secGrpRule.has_field('security_group_id', basestring)
             secGrpRule.has_field('protocol', basestring)
             secGrpRule.has_field('cidr', basestring)
             secGrpRule.has_field('from_port', int)
             secGrpRule.has_field('to_port', int)
             secGrpRule.has_field('created', basestring)
         assert_equal(self.testSecurityGroupRule.security_group_id,
                      self.testSecurityGroup.id)
         assert_equal(self.testSecurityGroupRule.protocol, "tcp")
         assert_equal(int(self.testSecurityGroupRule.from_port), 3306)
         assert_equal(int(self.testSecurityGroupRule.to_port), 3306)
         assert_equal(self.testSecurityGroupRule.cidr, "0.0.0.0/0")
     else:
         assert_not_equal(len(self.testSecurityGroup.rules), 0)
Beispiel #4
0
 def mgmt_instance_get(self):
     """Tests the mgmt get call works when the Nova server isn't ready."""
     api_instance = self.mgmt.show(self.id)
     # Print out all fields for extra info if the test fails.
     for name in dir(api_instance):
         print(str(name) + "=" + str(getattr(api_instance, name)))
     # Print out all fields for extra info if the test fails.
     for name in dir(api_instance):
         print(str(name) + "=" + str(getattr(api_instance, name)))
     with TypeCheck("instance", api_instance) as instance:
         instance.has_field('created', six.string_types)
         instance.has_field('deleted', bool)
         # If the instance hasn't been deleted, this should be false... but
         # lets avoid creating more ordering work.
         instance.has_field('deleted_at', (six.string_types, None))
         instance.has_field('flavor', dict, flavor_check)
         instance.has_field('datastore', dict, datastore_check)
         instance.has_field('guest_status', dict, guest_status_check)
         instance.has_field('id', six.string_types)
         instance.has_field('links', list)
         instance.has_field('name', six.string_types)
         # instance.has_field('server_status', six.string_types)
         instance.has_field('status', six.string_types)
         instance.has_field('tenant_id', six.string_types)
         instance.has_field('updated', six.string_types)
         # Can be None if no volume is given on this instance.
         instance.has_field('server', None)
         instance.has_field('volume', None)
Beispiel #5
0
 def test_datastore_list_attrs(self):
     datastores = self.rd_client.datastores.list()
     for datastore in datastores:
         with TypeCheck('Datastore', datastore) as check:
             check.has_field("id", basestring)
             check.has_field("name", basestring)
             check.has_field("links", list)
Beispiel #6
0
 def test_datastore_get_attrs(self):
     datastore = self.rd_client.datastores.get(test_config.dbaas_datastore)
     with TypeCheck('Datastore', datastore) as check:
         check.has_field("id", basestring)
         check.has_field("name", basestring)
         check.has_field("links", list)
     assert_equal(datastore.name, test_config.dbaas_datastore)
Beispiel #7
0
 def test_expected_get_configuration_parameter(self):
     # tests get on a single parameter to verify it has expected attributes
     param_name = 'key_buffer_size'
     allowed_config_params = [
         'name', 'restart_required', 'max', 'min', 'type', 'deleted',
         'deleted_at', 'datastore_version_id'
     ]
     param = instance_info.dbaas.configuration_parameters.get_parameter(
         instance_info.dbaas_datastore,
         instance_info.dbaas_datastore_version, param_name)
     resp, body = instance_info.dbaas.client.last_response
     print("params: %s" % param)
     print("resp: %s" % resp)
     print("body: %s" % body)
     attrcheck = AttrCheck()
     config_parameter_dict = json.loads(body.decode())
     print("config_parameter_dict: %s" % config_parameter_dict)
     attrcheck.contains_allowed_attrs(config_parameter_dict,
                                      allowed_config_params,
                                      msg="Get Configuration parameter")
     assert_equal(param_name, config_parameter_dict['name'])
     with TypeCheck('ConfigurationParameter', param) as parameter:
         parameter.has_field('name', six.string_types)
         parameter.has_field('restart_required', bool)
         parameter.has_field('max', six.integer_types)
         parameter.has_field('min', six.integer_types)
         parameter.has_field('type', six.string_types)
         parameter.has_field('datastore_version_id', six.text_type)
Beispiel #8
0
 def test_valid_configurations_create(self):
     # create a configuration with valid parameters
     expected_configs = self.expected_default_datastore_configs()
     values = json.dumps(expected_configs.get('valid_values'))
     expected_values = json.loads(values)
     result = instance_info.dbaas.configurations.create(
         CONFIG_NAME,
         values,
         CONFIG_DESC,
         datastore=instance_info.dbaas_datastore,
         datastore_version=instance_info.dbaas_datastore_version)
     resp, body = instance_info.dbaas.client.last_response
     assert_equal(resp.status, 200)
     with TypeCheck('Configuration', result) as configuration:
         configuration.has_field('name', six.string_types)
         configuration.has_field('description', six.string_types)
         configuration.has_field('values', dict)
         configuration.has_field('datastore_name', six.string_types)
         configuration.has_field('datastore_version_id', six.text_type)
         configuration.has_field('datastore_version_name', six.string_types)
     global configuration_info
     configuration_info = result
     assert_equal(configuration_info.name, CONFIG_NAME)
     assert_equal(configuration_info.description, CONFIG_DESC)
     assert_equal(configuration_info.values, expected_values)
Beispiel #9
0
    def test_create_cluster_successfuly(self):
        valid_request_body = [
            {"flavorRef": self.instance.dbaas_flavor_href,
             "volume": self.instance.volume},
            {"flavorRef": self.instance.dbaas_flavor_href,
             "volume": self.instance.volume}]

        self.cluster = self.rd_client.clusters.create(
            "test_cluster", self.instance.dbaas_datastore,
            self.instance.dbaas_datastore_version,
            instances=valid_request_body)

        with TypeCheck('Cluster', self.cluster) as check:
            check.has_field("id", basestring)
            check.has_field("name", basestring)
            check.has_field("datastore", dict)
            check.has_field("instances", list)
            check.has_field("links", list)
            check.has_field("created", unicode)
            check.has_field("updated", unicode)
            for instance in self.cluster.instances:
                isinstance(instance, dict)
                asserts.assert_is_not_none(instance['id'])
                asserts.assert_is_not_none(instance['links'])
                asserts.assert_is_not_none(instance['name'])
        asserts.assert_equal(200, self.rd_client.last_http_code)
Beispiel #10
0
 def test_datastore_version_list_attrs(self):
     versions = self.rd_client.datastore_versions.list(
         test_config.dbaas_datastore)
     for version in versions:
         with TypeCheck('DatastoreVersion', version) as check:
             check.has_field("id", basestring)
             check.has_field("name", basestring)
             check.has_field("links", list)
Beispiel #11
0
    def test_datastore_get(self):
        # Test get by name
        datastore_by_name = self.rd_client.datastores.get(
            test_config.dbaas_datastore)
        with TypeCheck('Datastore', datastore_by_name) as check:
            check.has_field("id", basestring)
            check.has_field("name", basestring)
            check.has_field("links", list)
        assert_equal(datastore_by_name.name, test_config.dbaas_datastore)

        # test get by id
        datastore_by_id = self.rd_client.datastores.get(datastore_by_name.id)
        with TypeCheck('Datastore', datastore_by_id) as check:
            check.has_field("id", basestring)
            check.has_field("name", basestring)
            check.has_field("links", list)
        assert_equal(datastore_by_id.id, datastore_by_name.id)
Beispiel #12
0
 def test_datastore_version_get_attrs(self):
     version = self.rd_client.datastore_versions.get(
         test_config.dbaas_datastore, test_config.dbaas_datastore_version)
     with TypeCheck('DatastoreVersion', version) as check:
         check.has_field("id", basestring)
         check.has_field("name", basestring)
         check.has_field("links", list)
     assert_equal(version.name, test_config.dbaas_datastore_version)
Beispiel #13
0
 def test_datastore_version_list_by_uuid(self):
     versions = self.rd_client.datastore_versions.list(
         self.datastore_active.id)
     for version in versions:
         with TypeCheck('DatastoreVersion', version) as check:
             check.has_field("id", basestring)
             check.has_field("name", basestring)
             check.has_field("links", list)
Beispiel #14
0
 def test_datastore_version_list_attrs(self):
     versions = self.rd_client.datastore_versions.list(
         self.datastore_active.name)
     for version in versions:
         with TypeCheck('DatastoreVersion', version) as check:
             check.has_field("id", str)
             check.has_field("name", str)
             check.has_field("links", list)
Beispiel #15
0
 def test_datastore_version_get_by_uuid(self):
     version = self.rd_client.datastore_versions.get(
         self.datastore_active.id, self.datastore_version_active.id)
     with TypeCheck('DatastoreVersion', version) as check:
         check.has_field("id", basestring)
         check.has_field("name", basestring)
         check.has_field("datastore", basestring)
         check.has_field("links", list)
     assert_equal(version.name, self.datastore_version_active.name)
Beispiel #16
0
 def test_datastore_version_get_attrs(self):
     version = self.rd_client.datastore_versions.get(
         self.datastore_active.name, self.datastore_version_active.name)
     with TypeCheck('DatastoreVersion', version) as check:
         check.has_field("id", six.string_types)
         check.has_field("name", six.string_types)
         check.has_field("datastore", six.string_types)
         check.has_field("links", list)
     assert_equal(version.name, self.datastore_version_active.name)
Beispiel #17
0
 def test_created_security_group(self):
     assert_is_not_none(self.testSecurityGroup)
     with TypeCheck('SecurityGroup', self.testSecurityGroup) as secGrp:
         secGrp.has_field('id', basestring)
         secGrp.has_field('name', basestring)
         secGrp.has_field('description', basestring)
         secGrp.has_field('created', basestring)
         secGrp.has_field('updated', basestring)
     assert_equal(self.testSecurityGroup.name, self.secGroupName)
     assert_equal(self.testSecurityGroup.description,
                  self.secGroupDescription)
Beispiel #18
0
def mgmt_instance_get():
    """ Tests the mgmt instances index method. """
    reqs = Requirements(is_admin=True)
    user = CONFIG.users.find_user(reqs)
    client = create_dbaas_client(user)
    mgmt = client.management
    # Grab the info.id created by the main instance test which is stored in
    # a global.
    id = instance_info.id
    api_instance = mgmt.show(id)

    # Print out all fields for extra info if the test fails.
    for name in dir(api_instance):
        print(str(name) + "=" + str(getattr(api_instance, name)))
    with TypeCheck("instance", api_instance) as instance:
        instance.has_field('created', basestring)
        instance.has_field('deleted', bool)
        # If the instance hasn't been deleted, this should be false... but
        # lets avoid creating more ordering work.
        instance.has_field('deleted_at', (basestring, None))
        instance.has_field('flavor', dict, flavor_check)
        instance.has_field('guest_status', dict, guest_status_check)
        instance.has_field('id', basestring)
        instance.has_field('links', list)
        instance.has_field('name', basestring)
        #instance.has_field('server_status', basestring)
        instance.has_field('status', basestring)
        instance.has_field('tenant_id', basestring)
        instance.has_field('updated', basestring)
        # Can be None if no volume is given on this instance.
        if CONFIG.trove_volume_support:
            instance.has_field('volume', dict, volume_check)
        else:
            instance.has_field('volume', None)
        #TODO(tim-simpson): Validate additional fields, assert
        # no extra fields exist.
    with CollectionCheck("server", api_instance.server) as server:
        server.has_element("addresses", dict)
        server.has_element("deleted", bool)
        server.has_element("deleted_at", (basestring, None))
        server.has_element("host", basestring)
        server.has_element("id", basestring)
        server.has_element("local_id", int)
        server.has_element("name", basestring)
        server.has_element("status", basestring)
        server.has_element("tenant_id", basestring)
    if (CONFIG.trove_volume_support and CONFIG.trove_main_instance_has_volume):
        with CollectionCheck("volume", api_instance.volume) as volume:
            volume.has_element("attachments", list)
            volume.has_element("availability_zone", basestring)
            volume.has_element("created_at", (basestring, None))
            volume.has_element("id", basestring)
            volume.has_element("size", int)
            volume.has_element("status", basestring)
Beispiel #19
0
 def test_instance_get_shows_volume_info_while_mysql_is_down(self):
     """
     Confirms the get call behaves appropriately while an instance is
     down.
     """
     if not VOLUME_SUPPORT:
         raise SkipTest("Not testing volumes.")
     instance = self.dbaas.instances.get(self.instance_id)
     with TypeCheck("instance", instance) as check:
         check.has_field("volume", dict)
         check.true('size' in instance.volume)
         check.true('used' in instance.volume)
         check.true(isinstance(instance.volume.get('size', None), int))
         check.true(isinstance(instance.volume.get('used', None), float))
Beispiel #20
0
    def test_configurations_get(self):
        # test that the instance shows up on the assigned configuration
        result = instance_info.dbaas.configurations.get(configuration_info.id)
        assert_equal(configuration_info.id, result.id)
        assert_equal(configuration_info.name, result.name)
        assert_equal(configuration_info.description, result.description)

        # check the result field types
        with TypeCheck("configuration", result) as check:
            check.has_field("id", basestring)
            check.has_field("name", basestring)
            check.has_field("description", basestring)
            check.has_field("values", dict)

        print(result.values)
        with CollectionCheck("configuration_values", result.values) as check:
            # check each item has the correct type according to the rules
            for (item_key, item_val) in result.values.iteritems():
                print("item_key: %s" % item_key)
                print("item_val: %s" % item_val)
                dbaas = instance_info.dbaas
                param = dbaas.configuration_parameters.get_parameter(
                    instance_info.dbaas_datastore,
                    instance_info.dbaas_datastore_version,
                    item_key)
                if param.type == 'integer':
                    check.has_element(item_key, int)
                if param.type == 'string':
                    check.has_element(item_key, basestring)
                if param.type == 'boolean':
                    check.has_element(item_key, bool)

        # Test to make sure that another user is not able to GET this config
        reqs = Requirements(is_admin=False)
        test_auth_user = instance_info.user.auth_user
        other_user = CONFIG.users.find_user(reqs, black_list=[test_auth_user])
        other_user_tenant_id = other_user.tenant_id
        client_tenant_id = instance_info.user.tenant_id
        if other_user_tenant_id == client_tenant_id:
            other_user = CONFIG.users.find_user(reqs,
                                                black_list=[
                                                instance_info.user.auth_user,
                                                other_user])
        print(other_user)
        print(other_user.__dict__)
        other_client = create_dbaas_client(other_user)
        assert_raises(exceptions.NotFound, other_client.configurations.get,
                      configuration_info.id)
Beispiel #21
0
 def _assert_cluster_state(self, cluster_id, expected_state):
     cluster = self.auth_client.clusters.get(cluster_id)
     with TypeCheck('Cluster', cluster) as check:
         check.has_field("id", basestring)
         check.has_field("name", basestring)
         check.has_field("datastore", dict)
         check.has_field("instances", list)
         check.has_field("links", list)
         check.has_field("created", unicode)
         check.has_field("updated", unicode)
         for instance in cluster.instances:
             isinstance(instance, dict)
             self.assert_is_not_none(instance['id'])
             self.assert_is_not_none(instance['links'])
             self.assert_is_not_none(instance['name'])
     self.assert_equal(expected_state, cluster.task['name'],
                       'Unexpected cluster task name')
Beispiel #22
0
    def test_configurations_list(self):
        # test listing configurations show up
        result = instance_info.dbaas.configurations.list()
        for conf in result:
            with TypeCheck("Configuration", conf) as check:
                check.has_field('id', basestring)
                check.has_field('name', basestring)
                check.has_field('description', basestring)
                check.has_field('datastore_version_id', basestring)
                check.has_field('datastore_version_name', basestring)
                check.has_field('datastore_name', basestring)

        exists = [config for config in result if
                  config.id == configuration_info.id]
        assert_equal(1, len(exists))
        configuration = exists[0]
        assert_equal(configuration.id, configuration_info.id)
        assert_equal(configuration.name, configuration_info.name)
        assert_equal(configuration.description, configuration_info.description)
Beispiel #23
0
    def assert_configuration_show(self, config_id, config_name):
        result = self.auth_client.configurations.get(config_id)
        self.assert_equal(config_id, result.id, "Unexpected config id")
        self.assert_equal(config_name, result.name, "Unexpected config name")

        # check the result field types
        with TypeCheck("configuration", result) as check:
            check.has_field("id", basestring)
            check.has_field("name", basestring)
            check.has_field("description", basestring)
            check.has_field("values", dict)
            check.has_field("created", basestring)
            check.has_field("updated", basestring)
            check.has_field("instance_count", int)

        # check for valid timestamps
        self.assert_true(self._is_valid_timestamp(result.created),
                         'Created timestamp %s is invalid' % result.created)
        self.assert_true(self._is_valid_timestamp(result.updated),
                         'Updated timestamp %s is invalid' % result.updated)

        with CollectionCheck("configuration_values", result.values) as check:
            # check each item has the correct type according to the rules
            for (item_key, item_val) in result.values.iteritems():
                print("item_key: %s" % item_key)
                print("item_val: %s" % item_val)
                param = (
                    self.auth_client.configuration_parameters.get_parameter(
                        self.instance_info.dbaas_datastore,
                        self.instance_info.dbaas_datastore_version,
                        item_key))
                if param.type == 'integer':
                    check.has_element(item_key, int)
                if param.type == 'string':
                    check.has_element(item_key, basestring)
                if param.type == 'boolean':
                    check.has_element(item_key, bool)
Beispiel #24
0
    def test_configurations_get(self):
        """test that the instance shows up on the assigned configuration"""
        result = instance_info.dbaas.configurations.get(configuration_info.id)
        assert_equal(configuration_info.id, result.id)
        assert_equal(configuration_info.name, result.name)
        assert_equal(configuration_info.description, result.description)

        # check the result field types
        with TypeCheck("configuration", result) as check:
            check.has_field("id", six.string_types)
            check.has_field("name", six.string_types)
            check.has_field("description", six.string_types)
            check.has_field("values", dict)
            check.has_field("created", six.string_types)
            check.has_field("updated", six.string_types)
            check.has_field("instance_count", int)

        print(result.values)

        # check for valid timestamps
        assert_true(_is_valid_timestamp(result.created))
        assert_true(_is_valid_timestamp(result.updated))

        # check that created and updated timestamps differ, since
        # test_appending_to_existing_configuration should have changed the
        # updated timestamp
        if not CONFIG.fake_mode:
            assert_not_equal(result.created, result.updated)

        assert_equal(result.instance_count, 1)

        with CollectionCheck("configuration_values", result.values) as check:
            # check each item has the correct type according to the rules
            for (item_key, item_val) in result.values.items():
                print("item_key: %s" % item_key)
                print("item_val: %s" % item_val)
                dbaas = instance_info.dbaas
                param = dbaas.configuration_parameters.get_parameter(
                    instance_info.dbaas_datastore,
                    instance_info.dbaas_datastore_version, item_key)
                if param.type == 'integer':
                    check.has_element(item_key, int)
                if param.type == 'string':
                    check.has_element(item_key, six.string_types)
                if param.type == 'boolean':
                    check.has_element(item_key, bool)

        # Test to make sure that another user is not able to GET this config
        reqs = Requirements(is_admin=False)
        test_auth_user = instance_info.user.auth_user
        other_user = CONFIG.users.find_user(reqs, black_list=[test_auth_user])
        other_user_tenant_id = other_user.tenant_id
        client_tenant_id = instance_info.user.tenant_id
        if other_user_tenant_id == client_tenant_id:
            other_user = CONFIG.users.find_user(
                reqs, black_list=[instance_info.user.auth_user, other_user])
        print(other_user)
        print(other_user.__dict__)
        other_client = create_dbaas_client(other_user)
        assert_raises(exceptions.NotFound, other_client.configurations.get,
                      configuration_info.id)