Merge "Remove use_default_creds from preprov creds"
diff --git a/doc/source/index.rst b/doc/source/index.rst
index 10364db..98b006d 100644
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -51,6 +51,7 @@
account_generator
cleanup
javelin
+ workspace
==================
Indices and tables
diff --git a/doc/source/workspace.rst b/doc/source/workspace.rst
new file mode 100644
index 0000000..41325b2
--- /dev/null
+++ b/doc/source/workspace.rst
@@ -0,0 +1,5 @@
+-----------------
+Tempest Workspace
+-----------------
+
+.. automodule:: tempest.cmd.workspace
diff --git a/releasenotes/releasenotes/notes/add-tempest-workspaces-228a2ba4690b5589.yaml b/releasenotes/releasenotes/notes/add-tempest-workspaces-228a2ba4690b5589.yaml
new file mode 100644
index 0000000..9a1cef6
--- /dev/null
+++ b/releasenotes/releasenotes/notes/add-tempest-workspaces-228a2ba4690b5589.yaml
@@ -0,0 +1,5 @@
+---
+features:
+ - Adds tempest workspaces command and WorkspaceManager.
+ This is used to have a centralized repository for managing
+ different tempest configurations.
diff --git a/setup.cfg b/setup.cfg
index 24e0214..0bf493c 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -41,6 +41,7 @@
run-stress = tempest.cmd.run_stress:TempestRunStress
list-plugins = tempest.cmd.list_plugins:TempestListPlugins
verify-config = tempest.cmd.verify_tempest_config:TempestVerifyConfig
+ workspace = tempest.cmd.workspace:TempestWorkspace
oslo.config.opts =
tempest.config = tempest.config:list_opts
diff --git a/tempest/api/image/base.py b/tempest/api/image/base.py
index 5c87149..6d0fa8e 100644
--- a/tempest/api/image/base.py
+++ b/tempest/api/image/base.py
@@ -125,6 +125,8 @@
def setup_clients(cls):
super(BaseV2ImageTest, cls).setup_clients()
cls.client = cls.os.image_client_v2
+ cls.namespaces_client = cls.os.namespaces_client
+ cls.schemas_client = cls.os.schemas_client
class BaseV2MemberImageTest(BaseV2ImageTest):
diff --git a/tempest/api/image/v2/test_images.py b/tempest/api/image/v2/test_images.py
index 04582c6..1fb9c52 100644
--- a/tempest/api/image/v2/test_images.py
+++ b/tempest/api/image/v2/test_images.py
@@ -254,12 +254,12 @@
def test_get_image_schema(self):
# Test to get image schema
schema = "image"
- body = self.client.show_schema(schema)
+ body = self.schemas_client.show_schema(schema)
self.assertEqual("image", body['name'])
@test.idempotent_id('25c8d7b2-df21-460f-87ac-93130bcdc684')
def test_get_images_schema(self):
# Test to get images schema
schema = "images"
- body = self.client.show_schema(schema)
+ body = self.schemas_client.show_schema(schema)
self.assertEqual("images", body['name'])
diff --git a/tempest/api/image/v2/test_images_member.py b/tempest/api/image/v2/test_images_member.py
index 9ac708b..d8254f5 100644
--- a/tempest/api/image/v2/test_images_member.py
+++ b/tempest/api/image/v2/test_images_member.py
@@ -83,12 +83,12 @@
@test.idempotent_id('634dcc3f-f6e2-4409-b8fd-354a0bb25d83')
def test_get_image_member_schema(self):
- body = self.client.show_schema("member")
+ body = self.schemas_client.show_schema("member")
self.assertEqual("member", body['name'])
@test.idempotent_id('6ae916ef-1052-4e11-8d36-b3ae14853cbb')
def test_get_image_members_schema(self):
- body = self.client.show_schema("members")
+ body = self.schemas_client.show_schema("members")
self.assertEqual("members", body['name'])
@test.idempotent_id('cb961424-3f68-4d21-8e36-30ad66fb6bfb')
diff --git a/tempest/api/image/v2/test_images_metadefs_namespaces.py b/tempest/api/image/v2/test_images_metadefs_namespaces.py
index da0f4c1..f6d1bdc 100644
--- a/tempest/api/image/v2/test_images_metadefs_namespaces.py
+++ b/tempest/api/image/v2/test_images_metadefs_namespaces.py
@@ -31,38 +31,42 @@
name = [{'name': resource_name}]
namespace_name = data_utils.rand_name('namespace')
# create the metadef namespace
- body = self.client.create_namespace(namespace=namespace_name,
- visibility='public',
- description='Tempest',
- display_name=namespace_name,
- resource_type_associations=name,
- protected=True)
+ body = self.namespaces_client.create_namespace(
+ namespace=namespace_name,
+ visibility='public',
+ description='Tempest',
+ display_name=namespace_name,
+ resource_type_associations=name,
+ protected=True)
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
self._cleanup_namespace, namespace_name)
# get namespace details
- body = self.client.show_namespace(namespace_name)
+ body = self.namespaces_client.show_namespace(namespace_name)
self.assertEqual(namespace_name, body['namespace'])
self.assertEqual('public', body['visibility'])
# unable to delete protected namespace
- self.assertRaises(lib_exc.Forbidden, self.client.delete_namespace,
+ self.assertRaises(lib_exc.Forbidden,
+ self.namespaces_client.delete_namespace,
namespace_name)
# update the visibility to private and protected to False
- body = self.client.update_namespace(namespace=namespace_name,
- description='Tempest',
- visibility='private',
- display_name=namespace_name,
- protected=False)
+ body = self.namespaces_client.update_namespace(
+ namespace=namespace_name,
+ description='Tempest',
+ visibility='private',
+ display_name=namespace_name,
+ protected=False)
self.assertEqual('private', body['visibility'])
self.assertEqual(False, body['protected'])
# now able to delete the non-protected namespace
- self.client.delete_namespace(namespace_name)
+ self.namespaces_client.delete_namespace(namespace_name)
def _cleanup_namespace(self, namespace_name):
- body = self.client.show_namespace(namespace_name)
+ body = self.namespaces_client.show_namespace(namespace_name)
self.assertEqual(namespace_name, body['namespace'])
- body = self.client.update_namespace(namespace=namespace_name,
- description='Tempest',
- visibility='private',
- display_name=namespace_name,
- protected=False)
- self.client.delete_namespace(namespace_name)
+ body = self.namespaces_client.update_namespace(
+ namespace=namespace_name,
+ description='Tempest',
+ visibility='private',
+ display_name=namespace_name,
+ protected=False)
+ self.namespaces_client.delete_namespace(namespace_name)
diff --git a/tempest/clients.py b/tempest/clients.py
index 7fa4e5b..de9b88a 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -137,6 +137,8 @@
ImagesClient as ImagesV2Client
from tempest.services.image.v2.json.members_client import MembersClient \
as MembersClientV2
+from tempest.services.image.v2.json.namespaces_client import NamespacesClient
+from tempest.services.image.v2.json.schemas_client import SchemasClient
from tempest.services.object_storage.account_client import AccountClient
from tempest.services.object_storage.container_client import ContainerClient
from tempest.services.object_storage.object_client import ObjectClient
@@ -359,6 +361,22 @@
build_interval=CONF.image.build_interval,
build_timeout=CONF.image.build_timeout,
**self.default_params)
+ self.namespaces_client = NamespacesClient(
+ self.auth_provider,
+ CONF.image.catalog_type,
+ CONF.image.region or CONF.identity.region,
+ endpoint_type=CONF.image.endpoint_type,
+ build_interval=CONF.image.build_interval,
+ build_timeout=CONF.image.build_timeout,
+ **self.default_params)
+ self.schemas_client = SchemasClient(
+ self.auth_provider,
+ CONF.image.catalog_type,
+ CONF.image.region or CONF.identity.region,
+ endpoint_type=CONF.image.endpoint_type,
+ build_interval=CONF.image.build_interval,
+ build_timeout=CONF.image.build_timeout,
+ **self.default_params)
self.orchestration_client = OrchestrationClient(
self.auth_provider,
CONF.orchestration.catalog_type,
diff --git a/tempest/cmd/init.py b/tempest/cmd/init.py
index 633b9e9..77d62d3 100644
--- a/tempest/cmd/init.py
+++ b/tempest/cmd/init.py
@@ -21,6 +21,8 @@
from oslo_log import log as logging
from six import moves
+from tempest.cmd.workspace import WorkspaceManager
+
LOG = logging.getLogger(__name__)
TESTR_CONF = """[DEFAULT]
@@ -89,6 +91,10 @@
action='store_true', dest='show_global_dir',
help="Print the global config dir location, "
"then exit")
+ parser.add_argument('--name', help="The workspace name", default=None)
+ parser.add_argument('--workspace-path', default=None,
+ help="The path to the workspace file, the default "
+ "is ~/.tempest/workspace")
return parser
def generate_testr_conf(self, local_path):
@@ -114,15 +120,22 @@
config_parse.write(conf_file)
def copy_config(self, etc_dir, config_dir):
- shutil.copytree(config_dir, etc_dir)
+ if os.path.isdir(config_dir):
+ shutil.copytree(config_dir, etc_dir)
+ else:
+ LOG.warning("Global config dir %s can't be found" % config_dir)
def generate_sample_config(self, local_dir, config_dir):
- conf_generator = os.path.join(config_dir,
- 'config-generator.tempest.conf')
+ if os.path.isdir(config_dir):
+ conf_generator = os.path.join(config_dir,
+ 'config-generator.tempest.conf')
- subprocess.call(['oslo-config-generator', '--config-file',
- conf_generator],
- cwd=local_dir)
+ subprocess.call(['oslo-config-generator', '--config-file',
+ conf_generator],
+ cwd=local_dir)
+ else:
+ LOG.warning("Skipping sample config generation because global "
+ "config dir %s can't be found" % config_dir)
def create_working_dir(self, local_dir, config_dir):
# Create local dir if missing
@@ -159,6 +172,10 @@
subprocess.call(['testr', 'init'], cwd=local_dir)
def take_action(self, parsed_args):
+ workspace_manager = WorkspaceManager(parsed_args.workspace_path)
+ name = parsed_args.name or parsed_args.dir.split(os.path.sep)[-1]
+ workspace_manager.register_new_workspace(
+ name, parsed_args.dir, init=True)
config_dir = parsed_args.config_dir or get_tempest_default_config_dir()
if parsed_args.show_global_dir:
print("Global config dir is located at: %s" % config_dir)
diff --git a/tempest/cmd/workspace.py b/tempest/cmd/workspace.py
new file mode 100644
index 0000000..cc82284
--- /dev/null
+++ b/tempest/cmd/workspace.py
@@ -0,0 +1,218 @@
+# Copyright 2016 Rackspace
+#
+# 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.
+
+"""
+Manages Tempest workspaces
+
+This command is used for managing tempest workspaces
+
+Commands
+========
+
+list
+----
+Outputs the name and path of all known tempest workspaces
+
+register
+--------
+Registers a new tempest workspace via a given --name and --path
+
+rename
+------
+Renames a tempest workspace from --old-name to --new-name
+
+move
+----
+Changes the path of a given tempest workspace --name to --path
+
+remove
+------
+Deletes the entry for a given tempest workspace --name
+
+General Options
+===============
+
+ **--workspace_path**: Allows the user to specify a different location for the
+ workspace.yaml file containing the workspace definitions
+ instead of ~/.tempest/workspace.yaml
+"""
+
+import os
+import sys
+
+from cliff import command
+from oslo_concurrency import lockutils
+from oslo_log import log as logging
+import prettytable
+import yaml
+
+from tempest import config
+
+LOG = logging.getLogger(__name__)
+CONF = config.CONF
+
+
+class WorkspaceManager(object):
+ def __init__(self, path=None):
+ lockutils.get_lock_path(CONF)
+ self.path = path or os.path.join(
+ os.path.expanduser("~"), ".tempest", "workspace.yaml")
+ if not os.path.isdir(os.path.dirname(self.path)):
+ os.makedirs(self.path.rsplit(os.path.sep, 1)[0])
+ self.workspaces = {}
+
+ @lockutils.synchronized('workspaces', external=True)
+ def get_workspace(self, name):
+ """Returns the workspace that has the given name"""
+ self._populate()
+ return self.workspaces.get(name)
+
+ @lockutils.synchronized('workspaces', external=True)
+ def rename_workspace(self, old_name, new_name):
+ self._populate()
+ self._name_exists(old_name)
+ self._workspace_name_exists(new_name)
+ self.workspaces[new_name] = self.workspaces.pop(old_name)
+ self._write_file()
+
+ @lockutils.synchronized('workspaces', external=True)
+ def move_workspace(self, name, path):
+ self._populate()
+ path = os.path.abspath(os.path.expanduser(path))
+ self._name_exists(name)
+ self._validate_path(path)
+ self.workspaces[name] = path
+ self._write_file()
+
+ def _name_exists(self, name):
+ if name not in self.workspaces:
+ print("A workspace was not found with name: {0}".format(name))
+ sys.exit(1)
+
+ @lockutils.synchronized('workspaces', external=True)
+ def remove_workspace(self, name):
+ self._populate()
+ self._name_exists(name)
+ self.workspaces.pop(name)
+ self._write_file()
+
+ @lockutils.synchronized('workspaces', external=True)
+ def list_workspaces(self):
+ self._populate()
+ self._validate_workspaces()
+ return self.workspaces
+
+ def _workspace_name_exists(self, name):
+ if name in self.workspaces:
+ print("A workspace already exists with name: {0}.".format(
+ name))
+ sys.exit(1)
+
+ def _validate_path(self, path):
+ if not os.path.exists(path):
+ print("Path does not exist.")
+ sys.exit(1)
+
+ @lockutils.synchronized('workspaces', external=True)
+ def register_new_workspace(self, name, path, init=False):
+ """Adds the new workspace and writes out the new workspace config"""
+ self._populate()
+ path = os.path.abspath(os.path.expanduser(path))
+ # This only happens when register is called from outside of init
+ if not init:
+ self._validate_path(path)
+ self._workspace_name_exists(name)
+ self.workspaces[name] = path
+ self._write_file()
+
+ def _validate_workspaces(self):
+ if self.workspaces is not None:
+ self.workspaces = {n: p for n, p in self.workspaces.items()
+ if os.path.exists(p)}
+ self._write_file()
+
+ def _write_file(self):
+ with open(self.path, 'w') as f:
+ f.write(yaml.dump(self.workspaces))
+
+ def _populate(self):
+ if not os.path.isfile(self.path):
+ return
+ with open(self.path, 'r') as f:
+ self.workspaces = yaml.load(f) or {}
+
+
+class TempestWorkspace(command.Command):
+ def take_action(self, parsed_args):
+ self.manager = WorkspaceManager(parsed_args.workspace_path)
+ if getattr(parsed_args, 'register', None):
+ self.manager.register_new_workspace(
+ parsed_args.name, parsed_args.path)
+ elif getattr(parsed_args, 'rename', None):
+ self.manager.rename_workspace(
+ parsed_args.old_name, parsed_args.new_name)
+ elif getattr(parsed_args, 'move', None):
+ self.manager.move_workspace(
+ parsed_args.name, parsed_args.path)
+ elif getattr(parsed_args, 'remove', None):
+ self.manager.remove_workspace(
+ parsed_args.name)
+ else:
+ self._print_workspaces()
+ sys.exit(0)
+
+ def get_description(self):
+ return 'Tempest workspace actions'
+
+ def get_parser(self, prog_name):
+ parser = super(TempestWorkspace, self).get_parser(prog_name)
+
+ parser.add_argument(
+ '--workspace-path', required=False, default=None,
+ help="The path to the workspace file, the default is "
+ "~/.tempest/workspace.yaml")
+
+ subparsers = parser.add_subparsers()
+
+ list_parser = subparsers.add_parser('list')
+ list_parser.set_defaults(list=True)
+
+ register_parser = subparsers.add_parser('register')
+ register_parser.add_argument('--name', required=True)
+ register_parser.add_argument('--path', required=True)
+ register_parser.set_defaults(register=True)
+
+ update_parser = subparsers.add_parser('rename')
+ update_parser.add_argument('--old-name', required=True)
+ update_parser.add_argument('--new-name', required=True)
+ update_parser.set_defaults(rename=True)
+
+ move_parser = subparsers.add_parser('move')
+ move_parser.add_argument('--name', required=True)
+ move_parser.add_argument('--path', required=True)
+ move_parser.set_defaults(move=True)
+
+ remove_parser = subparsers.add_parser('remove')
+ remove_parser.add_argument('--name', required=True)
+ remove_parser.set_defaults(remove=True)
+
+ return parser
+
+ def _print_workspaces(self):
+ output = prettytable.PrettyTable(["Name", "Path"])
+ if self.manager.list_workspaces() is not None:
+ for name, path in self.manager.list_workspaces().items():
+ output.add_row([name, path])
+
+ print(output)
diff --git a/tempest/services/image/v2/json/images_client.py b/tempest/services/image/v2/json/images_client.py
index 1014417..aae1cd0 100644
--- a/tempest/services/image/v2/json/images_client.py
+++ b/tempest/services/image/v2/json/images_client.py
@@ -132,58 +132,9 @@
self.expected_success(204, resp.status)
return rest_client.ResponseBody(resp)
- def show_schema(self, schema):
- url = 'schemas/%s' % schema
- resp, body = self.get(url)
- self.expected_success(200, resp.status)
- body = json.loads(body)
- return rest_client.ResponseBody(resp, body)
-
def list_resource_types(self):
url = 'metadefs/resource_types'
resp, body = self.get(url)
self.expected_success(200, resp.status)
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
-
- def create_namespace(self, **kwargs):
- """Create a namespace.
-
- Available params: see http://developer.openstack.org/
- api-ref-image-v2.html#createNamespace-v2
- """
- data = json.dumps(kwargs)
- resp, body = self.post('metadefs/namespaces', data)
- self.expected_success(201, resp.status)
- body = json.loads(body)
- return rest_client.ResponseBody(resp, body)
-
- def show_namespace(self, namespace):
- url = 'metadefs/namespaces/%s' % namespace
- resp, body = self.get(url)
- self.expected_success(200, resp.status)
- body = json.loads(body)
- return rest_client.ResponseBody(resp, body)
-
- def update_namespace(self, namespace, **kwargs):
- """Update a namespace.
-
- Available params: see http://developer.openstack.org/
- api-ref-image-v2.html#updateNamespace-v2
- """
- # NOTE: On Glance API, we need to pass namespace on both URI
- # and a request body.
- params = {'namespace': namespace}
- params.update(kwargs)
- data = json.dumps(params)
- url = 'metadefs/namespaces/%s' % namespace
- resp, body = self.put(url, body=data)
- self.expected_success(200, resp.status)
- body = json.loads(body)
- return rest_client.ResponseBody(resp, body)
-
- def delete_namespace(self, namespace):
- url = 'metadefs/namespaces/%s' % namespace
- resp, _ = self.delete(url)
- self.expected_success(204, resp.status)
- return rest_client.ResponseBody(resp)
diff --git a/tempest/services/image/v2/json/namespaces_client.py b/tempest/services/image/v2/json/namespaces_client.py
new file mode 100644
index 0000000..97400e1
--- /dev/null
+++ b/tempest/services/image/v2/json/namespaces_client.py
@@ -0,0 +1,64 @@
+# Copyright 2013 IBM Corp.
+# 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.
+
+from oslo_serialization import jsonutils as json
+
+from tempest.lib.common import rest_client
+
+
+class NamespacesClient(rest_client.RestClient):
+ api_version = "v2"
+
+ def create_namespace(self, **kwargs):
+ """Create a namespace.
+
+ Available params: see http://developer.openstack.org/
+ api-ref-image-v2.html#createNamespace-v2
+ """
+ data = json.dumps(kwargs)
+ resp, body = self.post('metadefs/namespaces', data)
+ self.expected_success(201, resp.status)
+ body = json.loads(body)
+ return rest_client.ResponseBody(resp, body)
+
+ def show_namespace(self, namespace):
+ url = 'metadefs/namespaces/%s' % namespace
+ resp, body = self.get(url)
+ self.expected_success(200, resp.status)
+ body = json.loads(body)
+ return rest_client.ResponseBody(resp, body)
+
+ def update_namespace(self, namespace, **kwargs):
+ """Update a namespace.
+
+ Available params: see http://developer.openstack.org/
+ api-ref-image-v2.html#updateNamespace-v2
+ """
+ # NOTE: On Glance API, we need to pass namespace on both URI
+ # and a request body.
+ params = {'namespace': namespace}
+ params.update(kwargs)
+ data = json.dumps(params)
+ url = 'metadefs/namespaces/%s' % namespace
+ resp, body = self.put(url, body=data)
+ self.expected_success(200, resp.status)
+ body = json.loads(body)
+ return rest_client.ResponseBody(resp, body)
+
+ def delete_namespace(self, namespace):
+ url = 'metadefs/namespaces/%s' % namespace
+ resp, _ = self.delete(url)
+ self.expected_success(204, resp.status)
+ return rest_client.ResponseBody(resp)
diff --git a/tempest/services/image/v2/json/schemas_client.py b/tempest/services/image/v2/json/schemas_client.py
new file mode 100644
index 0000000..0c9db40
--- /dev/null
+++ b/tempest/services/image/v2/json/schemas_client.py
@@ -0,0 +1,29 @@
+# Copyright 2013 IBM Corp.
+# 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.
+
+from oslo_serialization import jsonutils as json
+
+from tempest.lib.common import rest_client
+
+
+class SchemasClient(rest_client.RestClient):
+ api_version = "v2"
+
+ def show_schema(self, schema):
+ url = 'schemas/%s' % schema
+ resp, body = self.get(url)
+ self.expected_success(200, resp.status)
+ body = json.loads(body)
+ return rest_client.ResponseBody(resp, body)
diff --git a/tempest/tests/cmd/test_workspace.py b/tempest/tests/cmd/test_workspace.py
new file mode 100644
index 0000000..c4bd7b2
--- /dev/null
+++ b/tempest/tests/cmd/test_workspace.py
@@ -0,0 +1,124 @@
+# Copyright 2016 Rackspace
+#
+# 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.
+
+import os
+import shutil
+import subprocess
+import tempfile
+
+from tempest.cmd.workspace import WorkspaceManager
+from tempest.lib.common.utils import data_utils
+from tempest.tests import base
+
+
+class TestTempestWorkspaceBase(base.TestCase):
+ def setUp(self):
+ super(TestTempestWorkspaceBase, self).setUp()
+ self.name = data_utils.rand_uuid()
+ self.path = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, self.path, ignore_errors=True)
+ store_dir = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, store_dir, ignore_errors=True)
+ self.store_file = os.path.join(store_dir, 'workspace.yaml')
+ self.workspace_manager = WorkspaceManager(path=self.store_file)
+ self.workspace_manager.register_new_workspace(self.name, self.path)
+
+
+class TestTempestWorkspace(TestTempestWorkspaceBase):
+ def _run_cmd_gets_return_code(self, cmd, expected):
+ process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ stdout, stderr = process.communicate()
+ return_code = process.returncode
+ msg = ("%s failled with:\nstdout: %s\nstderr: %s" % (' '.join(cmd),
+ stdout, stderr))
+ self.assertEqual(return_code, expected, msg)
+
+ def test_run_workspace_list(self):
+ cmd = ['tempest', 'workspace', '--workspace-path',
+ self.store_file, 'list']
+ self._run_cmd_gets_return_code(cmd, 0)
+
+ def test_run_workspace_register(self):
+ name = data_utils.rand_uuid()
+ path = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, path, ignore_errors=True)
+ cmd = ['tempest', 'workspace', '--workspace-path', self.store_file,
+ 'register', '--name', name, '--path', path]
+ self._run_cmd_gets_return_code(cmd, 0)
+ self.assertIsNotNone(self.workspace_manager.get_workspace(name))
+
+ def test_run_workspace_rename(self):
+ new_name = data_utils.rand_uuid()
+ cmd = ['tempest', 'workspace', '--workspace-path', self.store_file,
+ 'rename', "--old-name", self.name, '--new-name', new_name]
+ self._run_cmd_gets_return_code(cmd, 0)
+ self.assertIsNone(self.workspace_manager.get_workspace(self.name))
+ self.assertIsNotNone(self.workspace_manager.get_workspace(new_name))
+
+ def test_run_workspace_move(self):
+ new_path = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, new_path, ignore_errors=True)
+ cmd = ['tempest', 'workspace', '--workspace-path', self.store_file,
+ 'move', '--name', self.name, '--path', new_path]
+ self._run_cmd_gets_return_code(cmd, 0)
+ self.assertEqual(
+ self.workspace_manager.get_workspace(self.name), new_path)
+
+ def test_run_workspace_remove(self):
+ cmd = ['tempest', 'workspace', '--workspace-path', self.store_file,
+ 'remove', '--name', self.name]
+ self._run_cmd_gets_return_code(cmd, 0)
+ self.assertIsNone(self.workspace_manager.get_workspace(self.name))
+
+
+class TestTempestWorkspaceManager(TestTempestWorkspaceBase):
+ def setUp(self):
+ super(TestTempestWorkspaceManager, self).setUp()
+ self.name = data_utils.rand_uuid()
+ self.path = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, self.path, ignore_errors=True)
+ store_dir = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, store_dir, ignore_errors=True)
+ self.store_file = os.path.join(store_dir, 'workspace.yaml')
+ self.workspace_manager = WorkspaceManager(path=self.store_file)
+ self.workspace_manager.register_new_workspace(self.name, self.path)
+
+ def test_workspace_manager_get(self):
+ self.assertIsNotNone(self.workspace_manager.get_workspace(self.name))
+
+ def test_workspace_manager_rename(self):
+ new_name = data_utils.rand_uuid()
+ self.workspace_manager.rename_workspace(self.name, new_name)
+ self.assertIsNone(self.workspace_manager.get_workspace(self.name))
+ self.assertIsNotNone(self.workspace_manager.get_workspace(new_name))
+
+ def test_workspace_manager_move(self):
+ new_path = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, new_path, ignore_errors=True)
+ self.workspace_manager.move_workspace(self.name, new_path)
+ self.assertEqual(
+ self.workspace_manager.get_workspace(self.name), new_path)
+
+ def test_workspace_manager_remove(self):
+ self.workspace_manager.remove_workspace(self.name)
+ self.assertIsNone(self.workspace_manager.get_workspace(self.name))
+
+ def test_path_expansion(self):
+ name = data_utils.rand_uuid()
+ path = os.path.join("~", name)
+ os.makedirs(os.path.expanduser(path))
+ self.addCleanup(shutil.rmtree, path, ignore_errors=True)
+ self.workspace_manager.register_new_workspace(name, path)
+ self.assertIsNotNone(self.workspace_manager.get_workspace(name))