Mark 'rally use {deployment|task|verification}' deprecated
Mark methods from rally.cli.commands.use.UseCommands class deprecated and move their code to 'use' methods in classes DeploymentCommands, TaskCommands and VerifyCommands Change-Id: I9c79505c5fd1208b36503bcc9a6231e55822c8d0
This commit is contained in:
parent
08f4dabbbc
commit
703c1297e7
@ -489,4 +489,4 @@ complete -F _rally rally
|
|||||||
|
|
||||||
completion.append(""" OPTS["{cat}_{cmd}"]="{args}"\n""".format(
|
completion.append(""" OPTS["{cat}_{cmd}"]="{args}"\n""".format(
|
||||||
cat=category, cmd=name, args=args))
|
cat=category, cmd=name, args=args))
|
||||||
return bash_data % {"data": "".join(sorted(completion))}
|
return bash_data % {"data": "".join(sorted(completion))}
|
@ -26,8 +26,8 @@ import yaml
|
|||||||
|
|
||||||
from rally import api
|
from rally import api
|
||||||
from rally.cmd import cliutils
|
from rally.cmd import cliutils
|
||||||
from rally.cmd.commands import use
|
|
||||||
from rally.cmd import envutils
|
from rally.cmd import envutils
|
||||||
|
from rally.common import fileutils
|
||||||
from rally.common.i18n import _
|
from rally.common.i18n import _
|
||||||
from rally.common import utils
|
from rally.common import utils
|
||||||
from rally import db
|
from rally import db
|
||||||
@ -122,7 +122,7 @@ class DeploymentCommands(object):
|
|||||||
|
|
||||||
self.list(deployment_list=[deployment])
|
self.list(deployment_list=[deployment])
|
||||||
if do_use:
|
if do_use:
|
||||||
use.UseCommands().deployment(deployment["uuid"])
|
self.use(deployment["uuid"])
|
||||||
|
|
||||||
@cliutils.deprecated_args(
|
@cliutils.deprecated_args(
|
||||||
"--uuid", dest="deployment", type=str,
|
"--uuid", dest="deployment", type=str,
|
||||||
@ -255,6 +255,22 @@ class DeploymentCommands(object):
|
|||||||
return(1)
|
return(1)
|
||||||
cliutils.print_list(table_rows, headers)
|
cliutils.print_list(table_rows, headers)
|
||||||
|
|
||||||
|
def _update_openrc_deployment_file(self, deployment, endpoint):
|
||||||
|
openrc_path = os.path.expanduser("~/.rally/openrc-%s" % deployment)
|
||||||
|
with open(openrc_path, "w+") as env_file:
|
||||||
|
env_file.write("export OS_AUTH_URL=%(auth_url)s\n"
|
||||||
|
"export OS_USERNAME=%(username)s\n"
|
||||||
|
"export OS_PASSWORD=%(password)s\n"
|
||||||
|
"export OS_TENANT_NAME=%(tenant_name)s\n"
|
||||||
|
% endpoint)
|
||||||
|
if endpoint.get("region_name"):
|
||||||
|
env_file.write("export OS_REGION_NAME=%(region_name)s\n"
|
||||||
|
% endpoint)
|
||||||
|
expanded_path = os.path.expanduser("~/.rally/openrc")
|
||||||
|
if os.path.exists(expanded_path):
|
||||||
|
os.remove(expanded_path)
|
||||||
|
os.symlink(openrc_path, expanded_path)
|
||||||
|
|
||||||
@cliutils.args("--deployment", type=str, dest="deployment",
|
@cliutils.args("--deployment", type=str, dest="deployment",
|
||||||
help="UUID or name of the deployment")
|
help="UUID or name of the deployment")
|
||||||
def use(self, deployment):
|
def use(self, deployment):
|
||||||
@ -262,4 +278,21 @@ class DeploymentCommands(object):
|
|||||||
|
|
||||||
:param deployment: UUID or name of a deployment
|
:param deployment: UUID or name of a deployment
|
||||||
"""
|
"""
|
||||||
use.UseCommands().deployment(deployment)
|
try:
|
||||||
|
deployment = db.deployment_get(deployment)
|
||||||
|
print("Using deployment: %s" % deployment["uuid"])
|
||||||
|
fileutils.update_globals_file("RALLY_DEPLOYMENT",
|
||||||
|
deployment["uuid"])
|
||||||
|
self._update_openrc_deployment_file(
|
||||||
|
deployment["uuid"], deployment.get("admin") or
|
||||||
|
deployment.get("users")[0])
|
||||||
|
print ("~/.rally/openrc was updated\n\nHINTS:\n"
|
||||||
|
"* To get your cloud resources, run:\n\t"
|
||||||
|
"rally show [flavors|images|keypairs|networks|secgroups]\n"
|
||||||
|
"\n* To use standard OpenStack clients, set up your env by "
|
||||||
|
"running:\n\tsource ~/.rally/openrc\n"
|
||||||
|
" OpenStack clients are now configured, e.g run:\n\t"
|
||||||
|
"glance image-list")
|
||||||
|
except exceptions.DeploymentNotFound:
|
||||||
|
print("Deployment %s is not found." % deployment)
|
||||||
|
return 1
|
||||||
|
@ -30,8 +30,8 @@ from rally import api
|
|||||||
from rally.benchmark.processing import plot
|
from rally.benchmark.processing import plot
|
||||||
from rally.benchmark.processing import utils
|
from rally.benchmark.processing import utils
|
||||||
from rally.cmd import cliutils
|
from rally.cmd import cliutils
|
||||||
from rally.cmd.commands import use
|
|
||||||
from rally.cmd import envutils
|
from rally.cmd import envutils
|
||||||
|
from rally.common import fileutils
|
||||||
from rally.common.i18n import _
|
from rally.common.i18n import _
|
||||||
from rally.common import log as logging
|
from rally.common import log as logging
|
||||||
from rally.common import utils as rutils
|
from rally.common import utils as rutils
|
||||||
@ -219,7 +219,7 @@ class TaskCommands(object):
|
|||||||
abort_on_sla_failure=abort_on_sla_failure)
|
abort_on_sla_failure=abort_on_sla_failure)
|
||||||
self.detailed(task_id=task["uuid"])
|
self.detailed(task_id=task["uuid"])
|
||||||
if do_use:
|
if do_use:
|
||||||
use.UseCommands().task(task["uuid"])
|
self.use(task["uuid"])
|
||||||
except exceptions.InvalidConfigException:
|
except exceptions.InvalidConfigException:
|
||||||
return(1)
|
return(1)
|
||||||
|
|
||||||
@ -629,4 +629,6 @@ class TaskCommands(object):
|
|||||||
|
|
||||||
:param task: Task uuid.
|
:param task: Task uuid.
|
||||||
"""
|
"""
|
||||||
use.UseCommands().task(task)
|
print("Using task: %s" % task)
|
||||||
|
db.task_get(task)
|
||||||
|
fileutils.update_globals_file("RALLY_TASK", task)
|
||||||
|
@ -15,12 +15,14 @@
|
|||||||
|
|
||||||
""" Rally command: use """
|
""" Rally command: use """
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
from rally.cmd import cliutils
|
from rally.cmd import cliutils
|
||||||
from rally.common import fileutils
|
from rally.cmd.commands import deployment as cmd_deployment
|
||||||
from rally import db
|
from rally.cmd.commands import task
|
||||||
from rally import exceptions
|
from rally.cmd.commands import verify
|
||||||
|
from rally.common import log as logging
|
||||||
|
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class UseCommands(object):
|
class UseCommands(object):
|
||||||
@ -30,31 +32,6 @@ class UseCommands(object):
|
|||||||
task UUID in the commands requiring this parameter.
|
task UUID in the commands requiring this parameter.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _update_openrc_deployment_file(self, deployment, endpoint):
|
|
||||||
openrc_path = os.path.expanduser("~/.rally/openrc-%s" % deployment)
|
|
||||||
# NOTE(msdubov): In case of multiple endpoints write the first one.
|
|
||||||
with open(openrc_path, "w+") as env_file:
|
|
||||||
env_file.write("export OS_AUTH_URL=%(auth_url)s\n"
|
|
||||||
"export OS_USERNAME=%(username)s\n"
|
|
||||||
"export OS_PASSWORD=%(password)s\n"
|
|
||||||
"export OS_TENANT_NAME=%(tenant_name)s\n"
|
|
||||||
% endpoint)
|
|
||||||
if endpoint.get("region_name"):
|
|
||||||
env_file.write("export OS_REGION_NAME=%(region_name)s\n"
|
|
||||||
% endpoint)
|
|
||||||
expanded_path = os.path.expanduser("~/.rally/openrc")
|
|
||||||
if os.path.exists(expanded_path):
|
|
||||||
os.remove(expanded_path)
|
|
||||||
os.symlink(openrc_path, expanded_path)
|
|
||||||
|
|
||||||
def _update_attribute_in_global_file(self, attribute, value):
|
|
||||||
expanded_path = os.path.expanduser("~/.rally/globals")
|
|
||||||
fileutils.update_env_file(expanded_path, attribute, "%s\n" % value)
|
|
||||||
|
|
||||||
def _ensure_rally_configuration_dir_exists(self):
|
|
||||||
if not os.path.exists(os.path.expanduser("~/.rally/")):
|
|
||||||
os.makedirs(os.path.expanduser("~/.rally/"))
|
|
||||||
|
|
||||||
@cliutils.deprecated_args(
|
@cliutils.deprecated_args(
|
||||||
"--uuid", dest="deployment", type=str,
|
"--uuid", dest="deployment", type=str,
|
||||||
required=False, help="UUID of the deployment.")
|
required=False, help="UUID of the deployment.")
|
||||||
@ -68,25 +45,9 @@ class UseCommands(object):
|
|||||||
|
|
||||||
:param deployment: UUID or name of a deployment
|
:param deployment: UUID or name of a deployment
|
||||||
"""
|
"""
|
||||||
|
LOG.warning("Deprecated command 'rally use deployment', "
|
||||||
try:
|
"'rally deployment use' should be used instead.")
|
||||||
deploy = db.deployment_get(deployment)
|
cmd_deployment.DeploymentCommands().use(deployment)
|
||||||
print("Using deployment: %s" % deploy["uuid"])
|
|
||||||
self._ensure_rally_configuration_dir_exists()
|
|
||||||
self._update_attribute_in_global_file("RALLY_DEPLOYMENT",
|
|
||||||
deploy["uuid"])
|
|
||||||
self._update_openrc_deployment_file(
|
|
||||||
deploy["uuid"], deploy.get("admin") or deploy.get("users")[0])
|
|
||||||
print ("~/.rally/openrc was updated\n\nHINTS:\n"
|
|
||||||
"* To get your cloud resources, run:\n\t"
|
|
||||||
"rally show [flavors|images|keypairs|networks|secgroups]\n"
|
|
||||||
"\n* To use standard OpenStack clients, set up your env by "
|
|
||||||
"running:\n\tsource ~/.rally/openrc\n"
|
|
||||||
" OpenStack clients are now configured, e.g run:\n\t"
|
|
||||||
"glance image-list")
|
|
||||||
except exceptions.DeploymentNotFound:
|
|
||||||
print("Deployment %s is not found." % deployment)
|
|
||||||
return 1
|
|
||||||
|
|
||||||
@cliutils.args("--uuid", type=str, dest="task_id", required=False,
|
@cliutils.args("--uuid", type=str, dest="task_id", required=False,
|
||||||
help="UUID of the task")
|
help="UUID of the task")
|
||||||
@ -95,10 +56,9 @@ class UseCommands(object):
|
|||||||
|
|
||||||
:param task_id: a UUID of task
|
:param task_id: a UUID of task
|
||||||
"""
|
"""
|
||||||
print("Using task: %s" % task_id)
|
LOG.warning("Deprecated command 'rally use task', "
|
||||||
self._ensure_rally_configuration_dir_exists()
|
"'rally task use' should be used instead.")
|
||||||
db.task_get(task_id)
|
task.TaskCommands().use(task_id)
|
||||||
self._update_attribute_in_global_file("RALLY_TASK", task_id)
|
|
||||||
|
|
||||||
@cliutils.args("--uuid", type=str, dest="verification_id", required=False,
|
@cliutils.args("--uuid", type=str, dest="verification_id", required=False,
|
||||||
help="UUID of the verification")
|
help="UUID of the verification")
|
||||||
@ -107,8 +67,6 @@ class UseCommands(object):
|
|||||||
|
|
||||||
:param verification_id: a UUID of verification
|
:param verification_id: a UUID of verification
|
||||||
"""
|
"""
|
||||||
print("Verification UUID: %s" % verification_id)
|
LOG.warning("Deprecated command 'rally use verification', "
|
||||||
self._ensure_rally_configuration_dir_exists()
|
"'rally verify use' should be used instead.")
|
||||||
db.verification_get(verification_id)
|
verify.VerifyCommands.use(verification_id)
|
||||||
self._update_attribute_in_global_file("RALLY_VERIFICATION",
|
|
||||||
verification_id)
|
|
||||||
|
@ -23,8 +23,8 @@ import six
|
|||||||
|
|
||||||
from rally import api
|
from rally import api
|
||||||
from rally.cmd import cliutils
|
from rally.cmd import cliutils
|
||||||
from rally.cmd.commands import use
|
|
||||||
from rally.cmd import envutils
|
from rally.cmd import envutils
|
||||||
|
from rally.common import fileutils
|
||||||
from rally.common.i18n import _
|
from rally.common.i18n import _
|
||||||
from rally import consts
|
from rally import consts
|
||||||
from rally import db
|
from rally import db
|
||||||
@ -82,7 +82,7 @@ class VerifyCommands(object):
|
|||||||
verification = api.Verification.verify(deployment, set_name, regex,
|
verification = api.Verification.verify(deployment, set_name, regex,
|
||||||
tempest_config)
|
tempest_config)
|
||||||
if do_use:
|
if do_use:
|
||||||
use.UseCommands().verification(verification["uuid"])
|
self.use(verification["uuid"])
|
||||||
|
|
||||||
def list(self):
|
def list(self):
|
||||||
"""Display all verifications table, started and finished."""
|
"""Display all verifications table, started and finished."""
|
||||||
@ -274,4 +274,6 @@ class VerifyCommands(object):
|
|||||||
|
|
||||||
:param verification: a UUID of verification
|
:param verification: a UUID of verification
|
||||||
"""
|
"""
|
||||||
use.UseCommands().verification(verification)
|
print("Verification UUID: %s" % verification)
|
||||||
|
db.verification_get(verification)
|
||||||
|
fileutils.update_globals_file("RALLY_VERIFICATION", verification)
|
||||||
|
@ -69,3 +69,16 @@ def update_env_file(path, env_key, env_value):
|
|||||||
output = _read_env_file(path, env_key)
|
output = _read_env_file(path, env_key)
|
||||||
output.append("%s=%s" % (env_key, env_value))
|
output.append("%s=%s" % (env_key, env_value))
|
||||||
_rewrite_env_file(path, output)
|
_rewrite_env_file(path, output)
|
||||||
|
|
||||||
|
|
||||||
|
def update_globals_file(key, value):
|
||||||
|
"""Update the globals variables file.
|
||||||
|
|
||||||
|
:param key: the key to update
|
||||||
|
:param value: the value to update
|
||||||
|
"""
|
||||||
|
dir = os.path.expanduser("~/.rally/")
|
||||||
|
if not os.path.exists(dir):
|
||||||
|
os.makedirs(dir)
|
||||||
|
expanded_path = os.path.join(dir, "globals")
|
||||||
|
update_env_file(expanded_path, key, "%s\n" % value)
|
||||||
|
@ -18,8 +18,10 @@ import os
|
|||||||
import mock
|
import mock
|
||||||
|
|
||||||
from rally.cmd.commands import deployment
|
from rally.cmd.commands import deployment
|
||||||
|
from rally.cmd import envutils
|
||||||
from rally import consts
|
from rally import consts
|
||||||
from rally import exceptions
|
from rally import exceptions
|
||||||
|
from tests.unit import fakes
|
||||||
from tests.unit import test
|
from tests.unit import test
|
||||||
|
|
||||||
|
|
||||||
@ -63,7 +65,7 @@ class DeploymentCommandsTestCase(test.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch("rally.cmd.commands.deployment.DeploymentCommands.list")
|
@mock.patch("rally.cmd.commands.deployment.DeploymentCommands.list")
|
||||||
@mock.patch("rally.cmd.commands.use.UseCommands.deployment")
|
@mock.patch("rally.cmd.commands.deployment.DeploymentCommands.use")
|
||||||
@mock.patch("rally.cmd.commands.deployment.api.Deployment.create",
|
@mock.patch("rally.cmd.commands.deployment.api.Deployment.create",
|
||||||
return_value=dict(uuid="uuid"))
|
return_value=dict(uuid="uuid"))
|
||||||
@mock.patch("rally.cmd.commands.deployment.open",
|
@mock.patch("rally.cmd.commands.deployment.open",
|
||||||
@ -203,7 +205,64 @@ class DeploymentCommandsTestCase(test.TestCase):
|
|||||||
self.assertRaises(exceptions.InvalidArgumentsException,
|
self.assertRaises(exceptions.InvalidArgumentsException,
|
||||||
self.deployment.show, None)
|
self.deployment.show, None)
|
||||||
|
|
||||||
@mock.patch("rally.cmd.commands.use.UseCommands.deployment")
|
@mock.patch("os.remove")
|
||||||
def test_use(self, mock_use_deployment):
|
@mock.patch("os.symlink")
|
||||||
self.deployment.use("fake_id")
|
@mock.patch("rally.cmd.commands.deployment.db.deployment_get",
|
||||||
mock_use_deployment.assert_called_once_with("fake_id")
|
return_value=fakes.FakeDeployment(
|
||||||
|
uuid="593b683c-4b16-4b2b-a56b-e162bd60f10b"))
|
||||||
|
@mock.patch("os.path.exists", return_value=True)
|
||||||
|
@mock.patch("rally.common.fileutils.update_env_file")
|
||||||
|
def test_use(self, mock_env, mock_path, mock_deployment,
|
||||||
|
mock_symlink, mock_remove):
|
||||||
|
deployment_id = mock_deployment.return_value["uuid"]
|
||||||
|
|
||||||
|
mock_deployment.return_value["admin"] = {
|
||||||
|
"auth_url": "fake_auth_url",
|
||||||
|
"username": "fake_username",
|
||||||
|
"password": "fake_password",
|
||||||
|
"tenant_name": "fake_tenant_name",
|
||||||
|
"region_name": None}
|
||||||
|
|
||||||
|
with mock.patch("rally.cmd.commands.deployment.open", mock.mock_open(),
|
||||||
|
create=True) as mock_file:
|
||||||
|
self.deployment.use(deployment_id)
|
||||||
|
self.assertEqual(2, mock_path.call_count)
|
||||||
|
mock_env.assert_called_once_with(os.path.expanduser(
|
||||||
|
"~/.rally/globals"),
|
||||||
|
"RALLY_DEPLOYMENT", "%s\n" % deployment_id)
|
||||||
|
mock_file.return_value.write.assert_called_once_with(
|
||||||
|
"export OS_AUTH_URL=fake_auth_url\n"
|
||||||
|
"export OS_USERNAME=fake_username\n"
|
||||||
|
"export OS_PASSWORD=fake_password\n"
|
||||||
|
"export OS_TENANT_NAME=fake_tenant_name\n")
|
||||||
|
mock_symlink.assert_called_once_with(
|
||||||
|
os.path.expanduser("~/.rally/openrc-%s" % deployment_id),
|
||||||
|
os.path.expanduser("~/.rally/openrc"))
|
||||||
|
mock_remove.assert_called_once_with(os.path.expanduser(
|
||||||
|
"~/.rally/openrc"))
|
||||||
|
|
||||||
|
@mock.patch("rally.cmd.commands.deployment.DeploymentCommands."
|
||||||
|
"_update_openrc_deployment_file")
|
||||||
|
@mock.patch("rally.common.fileutils.update_globals_file")
|
||||||
|
@mock.patch("rally.cmd.commands.deployment.db")
|
||||||
|
def test_use_by_name(self, mock_db, mock_update_openrc,
|
||||||
|
mock_update_globals):
|
||||||
|
fake_deployment = fakes.FakeDeployment(
|
||||||
|
uuid="fake_uuid",
|
||||||
|
admin="fake_endpoints")
|
||||||
|
mock_db.deployment_list.return_value = [fake_deployment]
|
||||||
|
mock_db.deployment_get.return_value = fake_deployment
|
||||||
|
status = self.deployment.use(deployment="fake_name")
|
||||||
|
self.assertIsNone(status)
|
||||||
|
mock_db.deployment_get.assert_called_once_with("fake_name")
|
||||||
|
mock_update_openrc.assert_called_once_with(
|
||||||
|
envutils.ENV_DEPLOYMENT, "fake_uuid")
|
||||||
|
mock_update_globals.assert_called_once_with(
|
||||||
|
"fake_uuid", "fake_endpoints")
|
||||||
|
|
||||||
|
@mock.patch("rally.cmd.commands.deployment.db.deployment_get")
|
||||||
|
def test_deployment_not_found(self, mock_deployment_get):
|
||||||
|
deployment_id = "e87e4dca-b515-4477-888d-5f6103f13b42"
|
||||||
|
mock_deployment_get.side_effect = exceptions.DeploymentNotFound(
|
||||||
|
uuid=deployment_id)
|
||||||
|
self.assertEqual(1, self.deployment.use(deployment_id))
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
import datetime as date
|
import datetime as date
|
||||||
|
import os.path
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
@ -596,7 +597,17 @@ class TaskCommandsTestCase(test.TestCase):
|
|||||||
mock_task_validate.assert_called_once_with("deployment",
|
mock_task_validate.assert_called_once_with("deployment",
|
||||||
mock_load.return_value)
|
mock_load.return_value)
|
||||||
|
|
||||||
@mock.patch("rally.cmd.commands.use.UseCommands.task")
|
@mock.patch("rally.common.fileutils._rewrite_env_file")
|
||||||
def test_use(self, mock_use_task):
|
@mock.patch("rally.cmd.commands.task.db.task_get", return_value=True)
|
||||||
self.task.use("fake_id")
|
def test_use(self, mock_task, mock_file):
|
||||||
mock_use_task.assert_called_once_with("fake_id")
|
task_id = "80422553-5774-44bd-98ac-38bd8c7a0feb"
|
||||||
|
self.task.use(task_id)
|
||||||
|
mock_file.assert_called_once_with(
|
||||||
|
os.path.expanduser("~/.rally/globals"),
|
||||||
|
["RALLY_TASK=%s\n" % task_id])
|
||||||
|
|
||||||
|
@mock.patch("rally.cmd.commands.task.db.task_get")
|
||||||
|
def test_use_not_found(self, mock_task):
|
||||||
|
task_id = "ddc3f8ba-082a-496d-b18f-72cdf5c10a14"
|
||||||
|
mock_task.side_effect = exceptions.TaskNotFound(uuid=task_id)
|
||||||
|
self.assertRaises(exceptions.TaskNotFound, self.task.use, task_id)
|
||||||
|
@ -13,14 +13,9 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from rally.cmd.commands import use
|
from rally.cmd.commands import use
|
||||||
from rally.cmd import envutils
|
|
||||||
from rally import exceptions
|
|
||||||
from tests.unit import fakes
|
|
||||||
from tests.unit import test
|
from tests.unit import test
|
||||||
|
|
||||||
MOD = "rally.cmd.commands.use."
|
MOD = "rally.cmd.commands.use."
|
||||||
@ -31,84 +26,17 @@ class UseCommandsTestCase(test.TestCase):
|
|||||||
super(UseCommandsTestCase, self).setUp()
|
super(UseCommandsTestCase, self).setUp()
|
||||||
self.use = use.UseCommands()
|
self.use = use.UseCommands()
|
||||||
|
|
||||||
@mock.patch("rally.cmd.commands.use.db.deployment_get",
|
@mock.patch("rally.cmd.commands.deployment.DeploymentCommands.use")
|
||||||
side_effect=exceptions.DeploymentNotFound())
|
def test_deployment(self, mock_deployment_use):
|
||||||
def test_deployment_use_no_args(self, mock_d_get):
|
self.use.deployment("fake_id")
|
||||||
status = self.use.deployment()
|
mock_deployment_use.assert_called_once_with("fake_id")
|
||||||
self.assertEqual(1, status)
|
|
||||||
|
|
||||||
@mock.patch(MOD + "UseCommands._update_openrc_deployment_file")
|
@mock.patch("rally.cmd.commands.task.TaskCommands.use")
|
||||||
@mock.patch(MOD + "UseCommands._update_attribute_in_global_file")
|
def test_task(self, mock_task_use):
|
||||||
@mock.patch(MOD + "UseCommands._ensure_rally_configuration_dir_exists")
|
self.use.task("fake_id")
|
||||||
@mock.patch(MOD + "db")
|
mock_task_use.assert_called_once_with("fake_id")
|
||||||
def test_deployment_use_by_name(self, m_db, m_ercde, m_uaigf, m_uodf):
|
|
||||||
fake_deployment = fakes.FakeDeployment(
|
|
||||||
uuid="fake_uuid",
|
|
||||||
admin="fake_endpoints")
|
|
||||||
m_db.deployment_list.return_value = [fake_deployment]
|
|
||||||
m_db.deployment_get.return_value = fake_deployment
|
|
||||||
status = self.use.deployment(deployment="fake_name")
|
|
||||||
self.assertIsNone(status)
|
|
||||||
m_db.deployment_get.assert_called_once_with("fake_name")
|
|
||||||
m_ercde.assert_called_once_with()
|
|
||||||
m_uaigf.assert_called_once_with(envutils.ENV_DEPLOYMENT, "fake_uuid")
|
|
||||||
m_uodf.assert_called_once_with("fake_uuid", "fake_endpoints")
|
|
||||||
|
|
||||||
@mock.patch("os.remove")
|
@mock.patch("rally.cmd.commands.verify.VerifyCommands.use")
|
||||||
@mock.patch("os.symlink")
|
def test_verification(self, mock_verify_use):
|
||||||
@mock.patch(
|
self.use.verification("fake_id")
|
||||||
MOD + "db.deployment_get",
|
mock_verify_use.assert_called_once_with("fake_id")
|
||||||
return_value=fakes.FakeDeployment(
|
|
||||||
uuid="593b683c-4b16-4b2b-a56b-e162bd60f10b"))
|
|
||||||
@mock.patch("os.path.exists", return_value=True)
|
|
||||||
@mock.patch(MOD + "fileutils.update_env_file")
|
|
||||||
def test_deployment(self, mock_env, mock_path, mock_deployment,
|
|
||||||
mock_symlink, mock_remove):
|
|
||||||
deployment_id = mock_deployment.return_value["uuid"]
|
|
||||||
|
|
||||||
mock_deployment.return_value["admin"] = {
|
|
||||||
"auth_url": "fake_auth_url",
|
|
||||||
"username": "fake_username",
|
|
||||||
"password": "fake_password",
|
|
||||||
"tenant_name": "fake_tenant_name",
|
|
||||||
"region_name": None}
|
|
||||||
|
|
||||||
with mock.patch("rally.cmd.commands.use.open", mock.mock_open(),
|
|
||||||
create=True) as mock_file:
|
|
||||||
self.use.deployment(deployment_id)
|
|
||||||
self.assertEqual(2, mock_path.call_count)
|
|
||||||
mock_env.assert_called_once_with(os.path.expanduser(
|
|
||||||
"~/.rally/globals"),
|
|
||||||
"RALLY_DEPLOYMENT", "%s\n" % deployment_id)
|
|
||||||
mock_file.return_value.write.assert_called_once_with(
|
|
||||||
"export OS_AUTH_URL=fake_auth_url\n"
|
|
||||||
"export OS_USERNAME=fake_username\n"
|
|
||||||
"export OS_PASSWORD=fake_password\n"
|
|
||||||
"export OS_TENANT_NAME=fake_tenant_name\n")
|
|
||||||
mock_symlink.assert_called_once_with(
|
|
||||||
os.path.expanduser("~/.rally/openrc-%s" % deployment_id),
|
|
||||||
os.path.expanduser("~/.rally/openrc"))
|
|
||||||
mock_remove.assert_called_once_with(os.path.expanduser(
|
|
||||||
"~/.rally/openrc"))
|
|
||||||
|
|
||||||
@mock.patch(MOD + "db.deployment_get")
|
|
||||||
def test_deployment_not_found(self, mock_deployment):
|
|
||||||
deployment_id = "e87e4dca-b515-4477-888d-5f6103f13b42"
|
|
||||||
mock_deployment.side_effect = exceptions.DeploymentNotFound(
|
|
||||||
uuid=deployment_id)
|
|
||||||
self.assertEqual(1, self.use.deployment(deployment_id))
|
|
||||||
|
|
||||||
@mock.patch(MOD + "fileutils._rewrite_env_file")
|
|
||||||
@mock.patch(MOD + "db.task_get", return_value=True)
|
|
||||||
def test_task(self, mock_task, mock_file):
|
|
||||||
task_id = "80422553-5774-44bd-98ac-38bd8c7a0feb"
|
|
||||||
self.use.task(task_id)
|
|
||||||
mock_file.assert_called_once_with(
|
|
||||||
os.path.expanduser("~/.rally/globals"),
|
|
||||||
["RALLY_TASK=%s\n" % task_id])
|
|
||||||
|
|
||||||
@mock.patch(MOD + "db.task_get")
|
|
||||||
def test_task_not_found(self, mock_task):
|
|
||||||
task_id = "ddc3f8ba-082a-496d-b18f-72cdf5c10a14"
|
|
||||||
mock_task.side_effect = exceptions.TaskNotFound(uuid=task_id)
|
|
||||||
self.assertRaises(exceptions.TaskNotFound, self.use.task, task_id)
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import datetime as date
|
import datetime as date
|
||||||
|
import os.path
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
@ -301,7 +302,20 @@ class VerifyCommandsTestCase(test.TestCase):
|
|||||||
mock_open.assert_called_once_with("results", "wb")
|
mock_open.assert_called_once_with("results", "wb")
|
||||||
mock_open.side_effect().write.assert_called_once_with("")
|
mock_open.side_effect().write.assert_called_once_with("")
|
||||||
|
|
||||||
@mock.patch("rally.cmd.commands.use.UseCommands.verification")
|
@mock.patch("rally.common.fileutils._rewrite_env_file")
|
||||||
def test_use(self, mock_use_verification):
|
@mock.patch("rally.cmd.commands.verify.db.verification_get",
|
||||||
self.verify.use("fake_id")
|
return_value=True)
|
||||||
mock_use_verification.assert_called_once_with("fake_id")
|
def test_use(self, mock_task, mock_file):
|
||||||
|
verification_id = "80422553-5774-44bd-98ac-38bd8c7a0feb"
|
||||||
|
self.verify.use(verification_id)
|
||||||
|
mock_file.assert_called_once_with(
|
||||||
|
os.path.expanduser("~/.rally/globals"),
|
||||||
|
["RALLY_VERIFICATION=%s\n" % verification_id])
|
||||||
|
|
||||||
|
@mock.patch("rally.cmd.commands.verify.db.verification_get")
|
||||||
|
def test_use_not_found(self, mock_verification_get):
|
||||||
|
verification_id = "ddc3f8ba-082a-496d-b18f-72cdf5c10a14"
|
||||||
|
mock_verification_get.side_effect = exceptions.NotFoundException(
|
||||||
|
uuid=verification_id)
|
||||||
|
self.assertRaises(exceptions.NotFoundException, self.verify.use,
|
||||||
|
verification_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user