unused file
This commit is contained in:
parent
a6bb256ed0
commit
333ec4146f
|
@ -1,222 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) 2013 Piston Cloud Computing, Inc.
|
||||
# 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.
|
||||
import os.path
|
||||
import sys
|
||||
import subprocess
|
||||
import argparse
|
||||
from textwrap import dedent
|
||||
from refstack.common.test import Test
|
||||
from refstack.common.cloud import Cloud
|
||||
|
||||
basedir = os.path.dirname(__file__)
|
||||
|
||||
def call(*args, **kwargs):
|
||||
"""subprocess.call with error checking."""
|
||||
assert not subprocess.call(*args, **kwargs)
|
||||
|
||||
class actions(argparse.Action):
|
||||
""" david please comment this """
|
||||
test_id = None
|
||||
params = {}
|
||||
|
||||
def __call__(self, parser, params, values, option_string=None, **kwargs):
|
||||
"""Triggered by -c command line argument """
|
||||
self.params = params
|
||||
setattr(self.params, self.dest, values)
|
||||
|
||||
self._print(self.params, verbose=False)
|
||||
|
||||
# action function mapping
|
||||
actions = { 'add' : self.add,
|
||||
'remove' : self.remove,
|
||||
'run' : self.run,
|
||||
'status' : self.status,
|
||||
'cancel' : self.cancel,
|
||||
'result' : self.result,
|
||||
'list-tests' : self.list_tests,
|
||||
'list-clouds' : self.list_clouds }
|
||||
|
||||
if len(self.params.command) > 1:
|
||||
print "Please only use one command at a time!\n\n"
|
||||
parser.print_help()
|
||||
sys.exit(1)
|
||||
|
||||
for command in self.params.command:
|
||||
if command in actions:
|
||||
actions[command]()
|
||||
|
||||
|
||||
def _print(self, output, verbose=False):
|
||||
"""print wrapper so -v and -s can be respected"""
|
||||
if not self.params.silent:
|
||||
if verbose is False:
|
||||
print(output)
|
||||
elif verbose is True and self.params.verbose > 0:
|
||||
print(output)
|
||||
|
||||
def add(self):
|
||||
""" add new cloud
|
||||
needs endpoint,test_user,test_key, admin_endpoint,admin_user,admin_key
|
||||
|
||||
refstack add --endpoint='http://127.0.0.1:5000/v3/' --test_user='demo'
|
||||
--test_key='pass' --admin_endpoint='http://127.0.0.1:5000/v3/'
|
||||
--admin_user='admin' --admin_key='pass'
|
||||
|
||||
outputs confirmation along with the cloud_id that was just created."""
|
||||
self._print('add command called')
|
||||
#self._print(self.params.endpoint)
|
||||
#for k,v in self.params.:
|
||||
# self._print(k + ': ' + v)
|
||||
c = Cloud()
|
||||
|
||||
c.add(self.params.endpoint,self.params.test_user,self.params.test_key,
|
||||
self.params.admin_endpoint,self.params.admin_user,self.params.admin_key)
|
||||
|
||||
self._print('cloud added ')
|
||||
|
||||
|
||||
def remove(self):
|
||||
""" add new cloud
|
||||
refstack remove --cloud_id 123
|
||||
|
||||
confirms that cloud-id 123 has been removed from the database as well as
|
||||
all tests assosiateed with it."""
|
||||
self._print('remove command called',True)
|
||||
|
||||
|
||||
def run(self):
|
||||
""" run test command
|
||||
|
||||
refstack run --cloud_id {123} --sha {sha}
|
||||
|
||||
triggers local run of tempest with specified cloud_id returns a
|
||||
test_id so that the user can check status or cancel the test"""
|
||||
self._print('run command called',True)
|
||||
|
||||
|
||||
def status(self):
|
||||
""" get the status of a running test
|
||||
|
||||
refstack status --test-id {123}
|
||||
"""
|
||||
self._print('status command called',True)
|
||||
|
||||
|
||||
def cancel(self):
|
||||
""" cancels a running test
|
||||
|
||||
refstack cancel --test-id {test_id}
|
||||
|
||||
stops the running test if it is running and displays output to user"""
|
||||
self._print('cancel command called',True)
|
||||
|
||||
|
||||
def result(self):
|
||||
""" outputs the results of a test
|
||||
|
||||
refstack results --test_id --format {screen|subunit}
|
||||
|
||||
if the test isn't finished it will say in progress otherwise will return
|
||||
subunit|screen output"""
|
||||
self._print('result command called',True)
|
||||
|
||||
|
||||
def list_tests(self):
|
||||
""" returns either a list of cached test results or a list of clouds
|
||||
|
||||
|
||||
"""
|
||||
self._print('list command called',True)
|
||||
|
||||
|
||||
def list_clouds(self):
|
||||
""" returns either a list of cached test results or a list of clouds
|
||||
|
||||
|
||||
"""
|
||||
self._print('list command called',True)
|
||||
|
||||
|
||||
def main():
|
||||
""" command line hook """
|
||||
parser = argparse.ArgumentParser(
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
description=dedent("""\
|
||||
This is a CLI utility for refstack
|
||||
|
||||
"""),
|
||||
epilog=dedent("""\
|
||||
Usage:
|
||||
|
||||
Refstack CLI:
|
||||
\n\n\n """))
|
||||
|
||||
# output options
|
||||
parser.add_argument('--verbose', '-v', action='count')
|
||||
parser.add_argument('--silent', '-s', action='store_true')
|
||||
|
||||
|
||||
# params for add endpoint,test_user,test_key, admin_endpoint,admin_user,admin_key
|
||||
parser.add_argument('--endpoint', nargs='?', type=str,
|
||||
default=None,
|
||||
help="""""")
|
||||
|
||||
parser.add_argument('--test_user', nargs='?', type=str,
|
||||
default=None,
|
||||
help="""""")
|
||||
|
||||
parser.add_argument('--test_key', nargs='?', type=str,
|
||||
default=None,
|
||||
help="""""")
|
||||
|
||||
parser.add_argument('--admin_endpoint', nargs='?', type=str,
|
||||
default=None,
|
||||
help="""""")
|
||||
|
||||
parser.add_argument('--admin_user', nargs='?', type=str,
|
||||
default=None,
|
||||
help="""""")
|
||||
|
||||
parser.add_argument('--admin_key', nargs='?', type=str,
|
||||
default=None,
|
||||
help="""""")
|
||||
|
||||
|
||||
parser.add_argument('--test-id', nargs='?', type=int,
|
||||
default=None,
|
||||
help="""id of the test you want to interact with.. if you are starting
|
||||
a new test you can leave this blank and it will
|
||||
return a new test_id""")
|
||||
|
||||
parser.add_argument('command', nargs='+', action=actions,
|
||||
help="Command to execute. ",
|
||||
choices=[ 'run','add','remove',
|
||||
'status','cancel','result',
|
||||
'list_clouds','list_tests'])
|
||||
|
||||
args = parser.parse_args()
|
||||
# validate input
|
||||
#option_given = not (args.c == None)
|
||||
|
||||
#if not option_given:
|
||||
# parser.print_help()
|
||||
# sys.exit(1)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue