Remove admin_domain_name from Credetials

admin_domain_name parameter is absent in Keystone Credentials
Add proper db migration

Change-Id: I6ac6b3a0e5cda07e48d3f9a1e9988c51070409c6
This commit is contained in:
Roman Vasilets 2016-08-29 13:28:40 +03:00
parent f010974f94
commit 7bf18f1d13
11 changed files with 184 additions and 22 deletions

View File

@ -0,0 +1,75 @@
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Remove admin domain name
Revision ID: 32fada9b2fde
Revises: 5b983f0c9b9a
Create Date: 2016-08-29 08:32:30.818019
"""
# revision identifiers, used by Alembic.
revision = "32fada9b2fde"
down_revision = "6ad4f426f005"
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
from rally.common.db.sqlalchemy import types as sa_types
from rally import exceptions
deployments_helper = sa.Table(
"deployments",
sa.MetaData(),
sa.Column("id", sa.Integer, primary_key=True, autoincrement=True),
sa.Column(
"config",
sa_types.MutableJSONEncodedDict,
default={},
nullable=False,
)
)
def upgrade():
connection = op.get_bind()
for deployment in connection.execute(deployments_helper.select()):
conf = deployment.config
if conf["type"] != "ExistingCloud":
continue
should_update = False
if "admin_domain_name" in conf["admin"]:
del conf["admin"]["admin_domain_name"]
should_update = True
if "users" in conf:
for user in conf["users"]:
if "admin_domain_name" in user:
del user["admin_domain_name"]
should_update = True
if should_update:
connection.execute(
deployments_helper.update().where(
deployments_helper.c.id == deployment.id).values(
config=conf))
def downgrade():
raise exceptions.DowngradeNotSupported()

View File

@ -22,8 +22,7 @@ class Credential(object):
project_name=None,
permission=consts.EndpointPermission.USER,
region_name=None, endpoint_type=None,
domain_name=None, endpoint=None,
user_domain_name=None, admin_domain_name="Default",
domain_name=None, endpoint=None, user_domain_name=None,
project_domain_name=None,
https_insecure=False, https_cacert=None):
self.auth_url = auth_url
@ -35,7 +34,6 @@ class Credential(object):
self.endpoint_type = endpoint_type
self.domain_name = domain_name
self.user_domain_name = user_domain_name
self.admin_domain_name = admin_domain_name
self.project_domain_name = project_domain_name
self.endpoint = endpoint
self.insecure = https_insecure
@ -51,7 +49,6 @@ class Credential(object):
"https_insecure": self.insecure,
"https_cacert": self.cacert,
"user_domain_name": self.user_domain_name,
"admin_domain_name": self.admin_domain_name,
"project_domain_name": self.project_domain_name}
if include_permission:
dct["permission"] = self.permission

View File

@ -104,7 +104,6 @@ class ExistingCloud(engine.Engine):
"password": {"type": "string"},
"domain_name": {"type": "string"},
"user_domain_name": {"type": "string"},
"admin_domain_name": {"type": "string"},
"project_name": {"type": "string"},
"project_domain_name": {"type": "string"},
},
@ -147,7 +146,6 @@ class ExistingCloud(engine.Engine):
endpoint=common.get("endpoint"),
domain_name=user.get("domain_name"),
user_domain_name=user.get("user_domain_name", None),
admin_domain_name=user.get("admin_domain_name", "Default"),
project_domain_name=user.get("project_domain_name", None),
https_insecure=common.get("https_insecure", False),
https_cacert=common.get("https_cacert")

View File

@ -194,8 +194,9 @@ class TempestConfig(utils.RandomNameGeneratorMixin):
self.credential["password"])
self.conf.set(section_name, "admin_project_name",
self.credential["tenant_name"])
# Keystone v3 related parameter
self.conf.set(section_name, "admin_domain_name",
self.credential["admin_domain_name"])
self.credential.get("user_domain_name", "Default"))
# Sahara has two service types: 'data_processing' and 'data-processing'.
# 'data_processing' is deprecated, but it can be used in previous OpenStack

View File

@ -7,7 +7,6 @@
"username": "admin",
"password": "myadminpass",
"user_domain_name": "admin",
"admin_domain_name": "default",
"project_name": "admin",
"project_domain_name": "admin"
},

View File

@ -323,7 +323,7 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"auth_url": "http://example.com:5000/v2.0",
"region_name": "RegionOne",
"type": "ExistingCloud",
"endpoint_type": "internal"}
"endpoint_type": "internal"},
}
deployment_table = db_utils.get_table(engine, "deployments")
@ -532,3 +532,102 @@ class MigrationWalkTestCase(rtest.DBTestCase,
deployment_table.delete().where(
deployment_table.c.uuid == "my_deployment")
)
def _pre_upgrade_32fada9b2fde(self, engine):
self._32fada9b2fde_deployments = {
# right config which should not be changed after migration
"should-not-be-changed-1": {
"admin": {"username": "admin",
"password": "passwd",
"project_name": "admin"},
"auth_url": "http://example.com:5000/v3",
"region_name": "RegionOne",
"type": "ExistingCloud"},
# right config which should not be changed after migration
"should-not-be-changed-2": {
"admin": {"username": "admin",
"password": "passwd",
"tenant_name": "admin"},
"users": [{"username": "admin",
"password": "passwd",
"tenant_name": "admin"}],
"auth_url": "http://example.com:5000/v2.0",
"region_name": "RegionOne",
"type": "ExistingCloud"},
# not ExistingCloud config which should not be changed
"should-not-be-changed-3": {
"url": "example.com",
"type": "Something"},
# with `admin_domain_name` field
"with_admin_domain_name": {
"admin": {"username": "admin",
"password": "passwd",
"project_name": "admin",
"admin_domain_name": "admin"},
"auth_url": "http://example.com:5000/v3",
"region_name": "RegionOne",
"type": "ExistingCloud"},
}
deployment_table = db_utils.get_table(engine, "deployments")
deployment_status = consts.DeployStatus.DEPLOY_FINISHED
with engine.connect() as conn:
for deployment in self._32fada9b2fde_deployments:
conf = json.dumps(
self._32fada9b2fde_deployments[deployment])
conn.execute(
deployment_table.insert(),
[{"uuid": deployment, "name": deployment,
"config": conf,
"enum_deployments_status": deployment_status,
"credentials": six.b(json.dumps([])),
"users": six.b(json.dumps([]))
}])
def _check_32fada9b2fde(self, engine, data):
self.assertEqual("32fada9b2fde",
api.get_backend().schema_revision(engine=engine))
original_deployments = self._32fada9b2fde_deployments
deployment_table = db_utils.get_table(engine, "deployments")
with engine.connect() as conn:
deployments_found = conn.execute(
deployment_table.select()).fetchall()
for deployment in deployments_found:
# check deployment
self.assertIn(deployment.uuid, original_deployments)
self.assertIn(deployment.name, original_deployments)
config = json.loads(deployment.config)
if config != original_deployments[deployment.uuid]:
if deployment.uuid.startswith("should-not-be-changed"):
self.fail("Config of deployment '%s' is changes, but "
"should not." % deployment.uuid)
if "admin_domain_name" in deployment.config:
self.fail("Config of deployment '%s' should not "
"contain `admin_domain_name` field." %
deployment.uuid)
endpoint_type = (original_deployments[
deployment.uuid].get("endpoint_type"))
if endpoint_type in (None, "public"):
self.assertNotIn("endpoint_type", config)
else:
self.assertIn("endpoint_type", config)
self.assertEqual(endpoint_type,
config["endpoint_type"])
existing.ExistingCloud({"config": config}).validate()
else:
if not deployment.uuid.startswith("should-not-be-changed"):
self.fail("Config of deployment '%s' is not changes, "
"but should." % deployment.uuid)
# this deployment created at _pre_upgrade step is not needed
# anymore and we can remove it
conn.execute(
deployment_table.delete().where(
deployment_table.c.uuid == deployment.uuid)
)

View File

@ -37,8 +37,7 @@ class CredentialTestCase(test.TestCase):
"https_insecure": False,
"https_cacert": None,
"project_domain_name": None,
"user_domain_name": None,
"admin_domain_name": "Default"})
"user_domain_name": None})
def test_to_dict_with_include_permission(self):
credential = objects.Credential(
@ -58,8 +57,7 @@ class CredentialTestCase(test.TestCase):
"https_insecure": False,
"https_cacert": None,
"project_domain_name": None,
"user_domain_name": None,
"admin_domain_name": "Default"})
"user_domain_name": None})
def test_to_dict_with_kwarg_credential(self):
credential = objects.Credential(
@ -80,5 +78,4 @@ class CredentialTestCase(test.TestCase):
"https_insecure": False,
"https_cacert": None,
"project_domain_name": None,
"user_domain_name": None,
"admin_domain_name": "Default"})
"user_domain_name": None})

View File

@ -59,7 +59,6 @@ class TestExistingCloud(test.TestCase):
"project_name": "demo",
"project_domain_name": "Default",
"user_domain_name": "Default",
"admin_domain_name": "Default",
}
}
}
@ -116,7 +115,6 @@ class TestExistingCloud(test.TestCase):
# so we need to pop them from credentials.to_dict()
actual_credentials.pop("domain_name")
actual_credentials.pop("user_domain_name")
actual_credentials.pop("admin_domain_name")
actual_credentials.pop("project_domain_name")
self.assertEqual(admin_credential, actual_credentials)

View File

@ -416,7 +416,6 @@ class UserGeneratorTestCase(test.ScenarioTestCase):
excluded_keys = ["auth_url", "username", "password",
"tenant_name", "region_name",
"project_domain_name",
"admin_domain_name",
"user_domain_name"]
for key in (set(credential_dict.keys()) - set(excluded_keys)):
self.assertEqual(credential_dict[key],

View File

@ -42,7 +42,6 @@ FAKE_DEPLOYMENT_CONFIG = {
"domain_name": None,
"project_domain_name": "Default",
"user_domain_name": "Default",
"admin_domain_name": "Default"
},
"region_name": "RegionOne",
"endpoint_type": consts.EndpointType.INTERNAL,

View File

@ -38,9 +38,8 @@ CREDS = {
"auth_url": "http://test:5000/v2.0/",
"permission": "admin",
"region_name": "test",
"admin_domain_name": "Default",
"https_insecure": False,
"https_cacert": "/path/to/cacert/file"
"https_cacert": "/path/to/cacert/file",
}
}
@ -103,7 +102,8 @@ class TempestConfigTestCase(test.TestCase):
("admin_username", CREDS["admin"]["username"]),
("admin_password", CREDS["admin"]["password"]),
("admin_project_name", CREDS["admin"]["tenant_name"]),
("admin_domain_name", CREDS["admin"]["admin_domain_name"]))
("admin_domain_name",
CREDS["admin"].get("user_domain_name", "Default")))
result = self.tempest_conf.conf.items("auth")
for item in expected:
self.assertIn(item, result)