From ebf4e585a6bbc7a08c5e779ff9863436e44484d8 Mon Sep 17 00:00:00 2001 From: Taseer Date: Tue, 25 Apr 2017 17:18:27 +0500 Subject: Implement qtip workspace create Change-Id: Ibd4213a6c4c86a7f4e8f99b16cba5055a3abba39 Signed-off-by: Taseer Ahmed --- qtip/cli/commands/cmd_run.py | 16 ++++++ qtip/cli/commands/cmd_setup.py | 16 ++++++ qtip/cli/commands/cmd_workspace.py | 34 +++++++++++ qtip/cli/utils.py | 9 +++ resources/ansible_roles/qtip-workspace/ansible.cfg | 15 +++++ resources/ansible_roles/qtip-workspace/create.yml | 67 ++++++++++++++++++++++ resources/ansible_roles/qtip-workspace/hosts | 1 + .../ansible_roles/qtip-workspace/tasks/main.yml | 4 +- tests/integration/ansible.cfg | 15 ----- tests/integration/hosts | 1 - tests/integration/workspace-create.yml | 67 ---------------------- 11 files changed, 160 insertions(+), 85 deletions(-) create mode 100644 qtip/cli/commands/cmd_run.py create mode 100644 qtip/cli/commands/cmd_setup.py create mode 100644 qtip/cli/commands/cmd_workspace.py create mode 100644 resources/ansible_roles/qtip-workspace/ansible.cfg create mode 100644 resources/ansible_roles/qtip-workspace/create.yml create mode 100644 resources/ansible_roles/qtip-workspace/hosts delete mode 100644 tests/integration/ansible.cfg delete mode 100644 tests/integration/hosts delete mode 100644 tests/integration/workspace-create.yml diff --git a/qtip/cli/commands/cmd_run.py b/qtip/cli/commands/cmd_run.py new file mode 100644 index 00000000..d1b96d4f --- /dev/null +++ b/qtip/cli/commands/cmd_run.py @@ -0,0 +1,16 @@ +############################################################################## +# Copyright (c) 2017 taseer94@gmail.com and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + + +import click + + +@click.command('run', help='Run performance tests') +def cli(): + pass diff --git a/qtip/cli/commands/cmd_setup.py b/qtip/cli/commands/cmd_setup.py new file mode 100644 index 00000000..586a4a72 --- /dev/null +++ b/qtip/cli/commands/cmd_setup.py @@ -0,0 +1,16 @@ +############################################################################## +# Copyright (c) 2017 taseer94@gmail.com and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + + +import click + + +@click.command('setup', help='Setup QTIP workspace') +def cli(): + pass diff --git a/qtip/cli/commands/cmd_workspace.py b/qtip/cli/commands/cmd_workspace.py new file mode 100644 index 00000000..9636f7fb --- /dev/null +++ b/qtip/cli/commands/cmd_workspace.py @@ -0,0 +1,34 @@ +############################################################################## +# Copyright (c) 2017 taseer94@gmail.com and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + + +import click +import os + +from qtip.cli import utils + + +@click.group() +def cli(): + """ Manage QTIP workspace """ + pass + + +@cli.command("create", help="Create QTIP workspace") +def create(): + extra_vars = { + 'qtip_package': utils.QTIP_PACKAGE, + 'cwd': os.getcwd() + } + os.system("ANSIBLE_ROLES_PATH={qtip_package}/{roles_path} ansible-playbook" + " {qtip_package}/{roles_path}/qtip-workspace/create.yml" + " --extra-vars '{extra_vars}'" + "".format(qtip_package=utils.QTIP_PACKAGE, + roles_path=utils.ROLES_PATH, + extra_vars=utils.join_vars(**extra_vars))) diff --git a/qtip/cli/utils.py b/qtip/cli/utils.py index a7473236..832e5ba9 100644 --- a/qtip/cli/utils.py +++ b/qtip/cli/utils.py @@ -9,10 +9,19 @@ from jinja2 import Environment from jinja2 import FileSystemLoader +import os from os import path from prettytable import PrettyTable +QTIP_PACKAGE = path.join(path.dirname(__file__), os.pardir, os.pardir) +ROLES_PATH = 'resources/ansible_roles' + + +def join_vars(**kwargs): + return " ".join(["{}={}".format(variable, value) for variable, value in kwargs.items()]) + + def table(name, components): """ Return a PrettyTable for component listing """ table = PrettyTable([name]) diff --git a/resources/ansible_roles/qtip-workspace/ansible.cfg b/resources/ansible_roles/qtip-workspace/ansible.cfg new file mode 100644 index 00000000..74075909 --- /dev/null +++ b/resources/ansible_roles/qtip-workspace/ansible.cfg @@ -0,0 +1,15 @@ +# config file for ansible -- https://ansible.com/ +# =============================================== + +# nearly all parameters can be overridden in ansible-playbook +# or with command line flags. ansible will read ANSIBLE_CONFIG, +# ansible.cfg in the current working directory, .ansible.cfg in +# the home directory or /etc/ansible/ansible.cfg, whichever it +# finds first + +[defaults] + +# some basic default values... + +inventory = hosts +roles_path = ../../resources/ansible_roles diff --git a/resources/ansible_roles/qtip-workspace/create.yml b/resources/ansible_roles/qtip-workspace/create.yml new file mode 100644 index 00000000..66a8cf36 --- /dev/null +++ b/resources/ansible_roles/qtip-workspace/create.yml @@ -0,0 +1,67 @@ +############################################################################## +# Copyright (c) 2017 ZTE Corporation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +--- +- hosts: localhost + + gather_facts: no + + vars_prompt: + + - name: pod_name + prompt: 'name of the pod under test (used in reporting)' + default: qtip-pod + private: no + + - name: scenario + prompt: 'scenario deployed in the pod:' + default: default + private: no + + - name: installer + prompt: 'installer type of the pod (apex|fuel)' + default: fuel + private: no + + - name: installer_master_host + prompt: 'master host/vm of the installer (accessible by `ssh `)' + private: no + + - name: workspace + prompt: 'workspace name (new directory will be created)' + default: workspace + private: no + + roles: + + - role: qtip-workspace + + # modify or override variables to customize the workspace + + # opnfv environment + +# installer: apex # +# installer_master_host: apex-virtual # make sure you can login it with key authentication + + # set testapi_url to enable reportint to testapi + +# testapi_url: http://localhost:8000/api/v1 + + # report variables + +# project_name: qtip +# case_name: compute +# pod_name: "{{ pod_name|default('qtip-pod') }}" +# scenario: "{{ scenario|default('generic') }}" +# version: master +# scenario: demo + + # qtip settings + + qtip_package: ../../.. # relative path from **workspace**, not current directory diff --git a/resources/ansible_roles/qtip-workspace/hosts b/resources/ansible_roles/qtip-workspace/hosts new file mode 100644 index 00000000..2302edae --- /dev/null +++ b/resources/ansible_roles/qtip-workspace/hosts @@ -0,0 +1 @@ +localhost ansible_connection=local diff --git a/resources/ansible_roles/qtip-workspace/tasks/main.yml b/resources/ansible_roles/qtip-workspace/tasks/main.yml index 4331468d..4fa60061 100644 --- a/resources/ansible_roles/qtip-workspace/tasks/main.yml +++ b/resources/ansible_roles/qtip-workspace/tasks/main.yml @@ -9,7 +9,7 @@ - name: creating directories file: - path: "{{ workspace }}/{{ item.path }}" + path: "{{ cwd }}/{{ workspace }}/{{ item.path }}" state: directory force: yes with_filetree: template/ @@ -18,7 +18,7 @@ - name: templating files template: src: "{{ item.src }}" - dest: "{{ workspace }}/{{ item.path }}" + dest: "{{ cwd }}/{{ workspace }}/{{ item.path }}" force: yes with_filetree: template/ when: item.state == 'file' diff --git a/tests/integration/ansible.cfg b/tests/integration/ansible.cfg deleted file mode 100644 index 74075909..00000000 --- a/tests/integration/ansible.cfg +++ /dev/null @@ -1,15 +0,0 @@ -# config file for ansible -- https://ansible.com/ -# =============================================== - -# nearly all parameters can be overridden in ansible-playbook -# or with command line flags. ansible will read ANSIBLE_CONFIG, -# ansible.cfg in the current working directory, .ansible.cfg in -# the home directory or /etc/ansible/ansible.cfg, whichever it -# finds first - -[defaults] - -# some basic default values... - -inventory = hosts -roles_path = ../../resources/ansible_roles diff --git a/tests/integration/hosts b/tests/integration/hosts deleted file mode 100644 index 2302edae..00000000 --- a/tests/integration/hosts +++ /dev/null @@ -1 +0,0 @@ -localhost ansible_connection=local diff --git a/tests/integration/workspace-create.yml b/tests/integration/workspace-create.yml deleted file mode 100644 index 741d1df0..00000000 --- a/tests/integration/workspace-create.yml +++ /dev/null @@ -1,67 +0,0 @@ -############################################################################## -# Copyright (c) 2017 ZTE Corporation and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - ---- -- hosts: localhost - - gather_facts: no - - vars_prompt: - - - name: pod_name - prompt: 'name of the pod under test (used in reporting)' - default: qtip-pod - private: no - - - name: scenario - prompt: 'scenario deployed in the pod:' - default: default - private: no - - - name: installer - prompt: 'installer type of the pod (apex|fuel|other)' - default: fuel - private: no - - - name: installer_master_host - prompt: 'master host/vm of the installer (accessible by `ssh `)' - private: no - - - name: workspace - prompt: 'workspace name (new directory will be created)' - default: workspace - private: no - - roles: - - - role: qtip-workspace - - # modify or override variables to customize the workspace - - # opnfv environment - -# installer: apex # -# installer_master_host: apex-virtual # make sure you can login it with key authentication - - # set testapi_url to enable reportint to testapi - -# testapi_url: http://localhost:8000/api/v1 - - # report variables - -# project_name: qtip -# case_name: compute -# pod_name: "{{ pod_name|default('qtip-pod') }}" -# scenario: "{{ scenario|default('generic') }}" -# version: master -# scenario: demo - - # qtip settings - - qtip_package: ../../.. # relative path from **workspace**, not current directory -- cgit 1.2.3-korg