aboutsummaryrefslogtreecommitdiffstats
path: root/moonclient/moonclient
diff options
context:
space:
mode:
Diffstat (limited to 'moonclient/moonclient')
-rw-r--r--moonclient/moonclient/shell.py41
-rw-r--r--moonclient/moonclient/tests.py18
-rw-r--r--moonclient/moonclient/tests/tests_empty_policy_new_user.json20
-rw-r--r--moonclient/moonclient/tests/tests_empty_policy_nova.json12
-rw-r--r--moonclient/moonclient/tests/tests_external_commands.json24
5 files changed, 95 insertions, 20 deletions
diff --git a/moonclient/moonclient/shell.py b/moonclient/moonclient/shell.py
index fa675dd9..f3d87ba3 100644
--- a/moonclient/moonclient/shell.py
+++ b/moonclient/moonclient/shell.py
@@ -11,6 +11,42 @@ import os
from cliff.app import App
from cliff.commandmanager import CommandManager
+from cliff.formatters.base import ListFormatter, SingleFormatter
+
+
+class _JSONFormatter(ListFormatter, SingleFormatter):
+
+ def add_argument_group(self, parser):
+ group = parser.add_argument_group(title='json formatter')
+ group.add_argument(
+ '--noindent',
+ action='store_true',
+ dest='noindent',
+ help='whether to disable indenting the JSON'
+ )
+ group.add_argument(
+ '--projectname',
+ help='Set the project name'
+ )
+
+ def emit_list(self, column_names, data, stdout, parsed_args):
+ items = []
+ import time
+ for item in data:
+ element = dict(zip(column_names, item))
+ element["project_name"] = parsed_args.projectname
+ element["name"] = element.pop("test_name")
+ element["url"] = ""
+ element["_id"] = ""
+ element["creation_date"] = time.strftime("%Y-%m-%d %H:%M:%S")
+ items.append(element)
+ indent = None if parsed_args.noindent else 2
+ json.dump({"testcases": items}, stdout, indent=indent)
+
+ def emit_one(self, column_names, data, stdout, parsed_args):
+ one = dict(zip(column_names, data))
+ indent = None if parsed_args.noindent else 2
+ json.dump(one, stdout, indent=indent)
def get_env_creds(admin_token=False):
@@ -70,7 +106,7 @@ class MoonClient(App):
def __init__(self):
super(MoonClient, self).__init__(
description='Moon Python Client',
- version='0.1',
+ version='0.2.0',
command_manager=CommandManager('moon.client'),
)
creds = get_env_creds()
@@ -230,6 +266,8 @@ class MoonClient(App):
data = self.get_url("/v3/auth/tokens", post_data=self.post)
if "token" not in data:
raise Exception("Authentication problem ({})".format(data))
+ from cliff.formatters.json_format import JSONFormatter
+ JSONFormatter = _JSONFormatter
def prepare_to_run_command(self, cmd):
self.log.debug('prepare_to_run_command %s', cmd.__class__.__name__)
@@ -238,6 +276,7 @@ class MoonClient(App):
self.log.debug('clean_up %s', cmd.__class__.__name__)
if err:
self.log.debug('got an error: %s', err)
+ self.log.debug("result: {}".format(result))
def main(argv=sys.argv[1:]):
diff --git a/moonclient/moonclient/tests.py b/moonclient/moonclient/tests.py
index 5a33130c..f312eed2 100644
--- a/moonclient/moonclient/tests.py
+++ b/moonclient/moonclient/tests.py
@@ -28,12 +28,17 @@ class TestsLaunch(Lister):
def get_parser(self, prog_name):
parser = super(TestsLaunch, self).get_parser(prog_name)
parser.add_argument(
- '--stop-on-error',
+ '--stop-on-error', action="store_true",
help='Stop the test on the first error',
)
parser.add_argument(
+ '--self', action="store_true",
+ help='Execute all internal tests',
+ )
+ parser.add_argument(
'testfile',
metavar='<filename(s)>',
+ nargs='?',
help='Filenames that contains tests to run '
'(examples: /path/to/test.json, /path/to/directory/, '
'"/path/to/*-file.json" -- don\'t forget the quote)',
@@ -58,11 +63,12 @@ class TestsLaunch(Lister):
def take_action(self, parsed_args):
self.log.info("Write tests output to {}".format(self.logfile_name))
- if not parsed_args.testfile:
- self.log.error("You don't give a test filename.")
- raise Exception("Cannot execute tests.")
- if os.path.isfile(parsed_args.testfile):
- return self.test_file(parsed_args.testfile)
+ if parsed_args.self:
+ import sys
+ import moonclient # noqa
+ parsed_args.testfile = os.path.join(sys.modules['moonclient'].__path__[0], "tests")
+ if parsed_args.testfile and os.path.isfile(parsed_args.testfile):
+ return self.test_file(parsed_args.testfile)
else:
cpt = 1
filenames = []
diff --git a/moonclient/moonclient/tests/tests_empty_policy_new_user.json b/moonclient/moonclient/tests/tests_empty_policy_new_user.json
index 6caf34ee..2d24e02e 100644
--- a/moonclient/moonclient/tests/tests_empty_policy_new_user.json
+++ b/moonclient/moonclient/tests/tests_empty_policy_new_user.json
@@ -28,10 +28,16 @@
"description": "Force the admin role for the user demo on the project admin (for testing purpose)."
},
{
+ "name": "neutron net-list",
+ "external_command": "neutron net-list",
+ "result": "(?P<uuid_net>[\\w-]+)\\s+\\| public",
+ "description": "Get an Net ID"
+ },
+ {
"name": "nova boot new server",
- "external_command": "nova boot --flavor m1.tiny --image $uuid_image test_moonclient",
- "result": "\\| OS-EXT-STS\\:vm_state\\s+\\| building",
- "description": "Boot a new nova server."
+ "external_command": "nova boot --flavor m1.tiny --image $uuid_image --nic net-id=$uuid_net test_moonclient",
+ "result": "(?P<uuid_image>[\\w-]+)\\s+\\| cirros-0.",
+ "description": "Get an Image ID"
},
{
"name": "sleep",
@@ -3398,12 +3404,6 @@
"result": "\\| (?P<uuid_server>[\\w\\-]+)\\s+\\| test_moonclient\\s+\\| ACTIVE\\s+\\| [\\w\\-]+\\s+\\| Running",
"description": "Check that nova server is still in running state."
},
- {
- "name": "pause",
- "external_command": "read",
- "result": "",
- "description": "Pause"
- },
{
"name": "list tenant",
@@ -3564,4 +3564,4 @@
}
]
}
-} \ No newline at end of file
+}
diff --git a/moonclient/moonclient/tests/tests_empty_policy_nova.json b/moonclient/moonclient/tests/tests_empty_policy_nova.json
index 521b1f1d..e1781c1f 100644
--- a/moonclient/moonclient/tests/tests_empty_policy_nova.json
+++ b/moonclient/moonclient/tests/tests_empty_policy_nova.json
@@ -10,13 +10,19 @@
{
"name": "nova image-list",
"external_command": "nova image-list",
- "result": "(?P<uuid_image>[\\w-]+)\\s+\\| cirros-0.3.4-x86_64-uec",
+ "result": "(?P<uuid_image>[\\w-]+)\\s+\\| cirros-0.*",
"description": "Get an Image ID"
},
{
+ "name": "neutron net-list",
+ "external_command": "neutron net-list",
+ "result": "(?P<uuid_net>[\\w-]+)\\s+\\| public",
+ "description": "Get an Net ID"
+ },
+ {
"name": "nova boot new server",
- "external_command": "nova boot --flavor m1.micro --image $uuid_image test_moonclient",
- "result": "(?P<uuid_image>[\\w-]+)\\s+\\| cirros-0.3.4-x86_64-uec",
+ "external_command": "nova boot --flavor m1.tiny --image $uuid_image --nic net-id=$uuid_net test_moonclient",
+ "result": "(?P<uuid_image>[\\w-]+)\\s+\\| cirros-0.",
"description": "Get an Image ID"
},
{
diff --git a/moonclient/moonclient/tests/tests_external_commands.json b/moonclient/moonclient/tests/tests_external_commands.json
index bfb7ac1a..d94658cc 100644
--- a/moonclient/moonclient/tests/tests_external_commands.json
+++ b/moonclient/moonclient/tests/tests_external_commands.json
@@ -118,6 +118,30 @@
},
{
+ "name": "nova image-list",
+ "external_command": "nova image-list",
+ "result": "(?P<uuid_image>[\\w-]+)\\s+\\| cirros-0.",
+ "description": "Get an Image ID"
+ },
+ {
+ "name": "neutron net-list",
+ "external_command": "neutron net-list",
+ "result": "(?P<uuid_net>[\\w-]+)\\s+\\| public",
+ "description": "Get an Net ID"
+ },
+ {
+ "name": "nova boot new server",
+ "external_command": "nova boot --flavor m1.tiny --image $uuid_image --nic net-id=$uuid_net test_moonclient",
+ "result": "(?P<uuid_image>[\\w-]+)\\s+\\| cirros-0.",
+ "description": "Get an Image ID"
+ },
+ {
+ "name": "sleep",
+ "external_command": "sleep 10",
+ "result": "",
+ "description": "time for server to really boot"
+ },
+ {
"name": "check nova command",
"external_command": "nova list",
"result": "\\| (?P<uuid_server>[\\w\\-]+)\\s+\\| (?P<name_server>\\w+)\\s+\\| ACTIVE\\s+\\| [\\w\\-]+\\s+\\| Running",