summaryrefslogtreecommitdiffstats
path: root/deploy/cloud/deploy.py
blob: e00934bd91f9426a45afc9c6c71d035a01d40a1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
###############################################################################
# Copyright (c) 2015 Ericsson AB and others.
# szilard.cserey@ericsson.com
# 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 yaml
import io

from dea import DeploymentEnvironmentAdapter
from configure_environment import ConfigureEnvironment
from deployment import Deployment

from common import (
    R,
    exec_cmd,
    parse,
    check_file_exists,
    commafy,
    ArgParser,
    log,
)

YAML_CONF_DIR = '/var/lib/opnfv'


class Deploy(object):

    def __init__(self, dea_file, no_health_check, deploy_timeout,
                 no_deploy_environment):
        self.dea = DeploymentEnvironmentAdapter(dea_file)
        self.no_health_check = no_health_check
        self.deploy_timeout = deploy_timeout
        self.no_deploy_environment = no_deploy_environment
        self.macs_per_blade = {}
        self.blades = self.dea.get_node_ids()
        self.blade_node_dict = self.dea.get_blade_node_map()
        self.node_roles_dict = {}
        self.env_id = None
        self.wanted_release = self.dea.get_property('wanted_release')

    def assign_roles_to_cluster_node_ids(self):
        self.node_roles_dict = {}
        for blade, node in self.blade_node_dict.iteritems():
            if self.dea.get_node_roles(blade):
                roles = commafy(self.dea.get_node_roles(blade))
                self.node_roles_dict[node] = (roles, blade)

    def configure_environment(self):
        release_list = parse(exec_cmd('fuel release -l'))
        for release in release_list:
            if release[R['name']] == self.wanted_release:
                break
        config_env = ConfigureEnvironment(self.dea, YAML_CONF_DIR,
                                          release[R['id']],
                                          self.node_roles_dict)
        config_env.configure_environment()
        self.env_id = config_env.env_id

    def deploy_cloud(self):
        dep = Deployment(self.dea, YAML_CONF_DIR, self.env_id,
                         self.node_roles_dict, self.no_health_check,
                         self.deploy_timeout)
        if not self.no_deploy_environment:
            dep.deploy()
        else:
            log('Configuration is done. Deployment is not launched.')

    def deploy(self):

        self.assign_roles_to_cluster_node_ids()

        self.configure_environment()

        self.deploy_cloud()


def parse_arguments():
    parser = ArgParser(prog='python %s' % __file__)
    parser.add_argument('-nh', dest='no_health_check', action='store_true',
                        default=False,
                        help='Don\'t run health check after deployment')
    parser.add_argument('-dt', dest='deploy_timeout', action='store',
                        default=240, help='Deployment timeout (in minutes) '
                        '[default: 240]')
    parser.add_argument('-nde', dest='no_deploy_environment',
                        action='store_true', default=False,
                        help=('Do not launch environment deployment'))
    parser.add_argument('dea_file', action='store',
                        help='Deployment Environment Adapter: dea.yaml')

    args = parser.parse_args()
    check_file_exists(args.dea_file)

    kwargs = {'dea_file': args.dea_file,
              'no_health_check': args.no_health_check,
              'deploy_timeout': args.deploy_timeout,
              'no_deploy_environment': args.no_deploy_environment}
    return kwargs


def main():
    kwargs = parse_arguments()
    deploy = Deploy(**kwargs)
    deploy.deploy()

if __name__ == '__main__':
    main()
Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
.. This work is licensed under a Creative Commons Attribution 4.0 International
.. License.
.. http://creativecommons.org/licenses/by/4.0
.. (c) OPNFV, Huawei Technologies Co.,Ltd and others.

Yardstick Restful API
======================


Abstract
--------

Yardstick support restful API since Danube.


Available API
-------------

/yardstick/env/action
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Description: This API is used to prepare Yardstick test environment. For Euphrates, it supports:

1. Prepare yardstick test environment, including set external network environment variable, load Yardstick VM images and create flavors;
2. Start an InfluxDB Docker container and config Yardstick output to InfluxDB;
3. Start a Grafana Docker container and config it with the InfluxDB.

Which API to call will depend on the parameters.


Method: POST


Prepare Yardstick test environment
Example::

    {
        'action': 'prepareYardstickEnv'
    }

This is an asynchronous API. You need to call /yardstick/asynctask API to get the task result.


Start and config an InfluxDB docker container
Example::

    {
        'action': 'createInfluxDBContainer'
    }

This is an asynchronous API. You need to call /yardstick/asynctask API to get the task result.


Start and config a Grafana docker container
Example::

    {
        'action': 'createGrafanaContainer'
    }

This is an asynchronous API. You need to call /yardstick/asynctask API to get the task result.


/yardstick/asynctask
^^^^^^^^^^^^^^^^^^^^

Description: This API is used to get the status of asynchronous tasks


Method: GET


Get the status of asynchronous tasks
Example::

    http://localhost:8888/yardstick/asynctask?task_id=3f3f5e03-972a-4847-a5f8-154f1b31db8c

The returned status will be 0(running), 1(finished) and 2(failed).


/yardstick/testcases
^^^^^^^^^^^^^^^^^^^^

Description: This API is used to list all released Yardstick test cases.


Method: GET


Get a list of released test cases
Example::

    http://localhost:8888/yardstick/testcases


/yardstick/testcases/release/action
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Description: This API is used to run a Yardstick released test case.


Method: POST


Run a released test case
Example::

    {
        'action': 'runTestCase',
        'args': {
            'opts': {},
            'testcase': 'tc002'
        }
    }

This is an asynchronous API. You need to call /yardstick/results to get the result.


/yardstick/testcases/samples/action
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Description: This API is used to run a Yardstick sample test case.


Method: POST


Run a sample test case
Example::

    {
        'action': 'runTestCase',
        'args': {
            'opts': {},
            'testcase': 'ping'
        }
    }

This is an asynchronous API. You need to call /yardstick/results to get the result.


/yardstick/testcases/<testcase_name>/docs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Description: This API is used to the documentation of a certain released test case.


Method: GET


Get the documentation of a certain test case
Example::

    http://localhost:8888/yardstick/taskcases/opnfv_yardstick_tc002/docs


/yardstick/testsuites/action
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Description: This API is used to run a Yardstick test suite.


Method: POST


Run a test suite
Example::

    {
        'action': 'runTestSuite',
        'args': {
            'opts': {},
            'testcase': 'smoke'
        }
    }

This is an asynchronous API. You need to call /yardstick/results to get the result.


/yardstick/tasks/<task_id>/log

Description: This API is used to get the real time log of test case execution.


Method: GET


Get real time of test case execution
Example::

    http://localhost:8888/yardstick/tasks/14795be8-f144-4f54-81ce-43f4e3eab33f/log?index=0


/yardstick/results
^^^^^^^^^^^^^^^^^^

Description: This API is used to get the test results of tasks. If you call /yardstick/testcases/samples/action API, it will return a task id. You can use the returned task id to get the results by using this API.


Method: GET


Get test results of one task
Example::

    http://localhost:8888/yardstick/results?task_id=3f3f5e03-972a-4847-a5f8-154f1b31db8c

This API will return a list of test case result


/api/v2/yardstick/openrcs/action

Description: This API provides functionality of handling OpenStack credential file (openrc). For Euphrates, it supports:

1. Upload an openrc file for an OpenStack environment;
2. Update an openrc file;
3. Get openrc file information;
4. Delete an openrc file.

Which API to call will depend on the parameters.


METHOD: POST


Upload an openrc file for an OpenStack environment
Example::

    {
        'action': 'upload_openrc',
        'args': {
            'file': file,
            'environment_id': environment_id
        }
    }


METHOD: POST


Update an openrc file
Example::

    {
        'action': 'update_openrc',
        'args': {
            'openrc': {
                "EXTERNAL_NETWORK": "ext-net",
                "OS_AUTH_URL": "http://192.168.23.51:5000/v3",
                "OS_IDENTITY_API_VERSION": "3",
                "OS_IMAGE_API_VERSION": "2",
                "OS_PASSWORD": "console",
                "OS_PROJECT_DOMAIN_NAME": "default",
                "OS_PROJECT_NAME": "admin",
                "OS_USERNAME": "admin",
                "OS_USER_DOMAIN_NAME": "default"
            },
            'environment_id': environment_id
        }
    }


METHOD: GET

Get openrc file information
Example::

    http://localhost:8888/api/v2/yardstick/openrcs/5g6g3e02-155a-4847-a5f8-154f1b31db8c


METHOD: DELETE


Delete openrc file
Example::

    http://localhost:8888/api/v2/yardstick/openrcs/5g6g3e02-155a-4847-a5f8-154f1b31db8c


/api/v2/yardstick/pods/action

Description: This API provides functionality of handling Yardstick pod file (pod.yaml). For Euphrates, it supports:

1. Upload a pod file;
2. Get pod file information;
3. Delete an openrc file.

Which API to call will depend on the parameters.


METHOD: POST


Upload a pod.yaml file
Example::

    {
        'action': 'upload_pod_file',
        'args': {
            'file': file,
            'environment_id': environment_id
        }
    }


METHOD: GET

Get pod file information
Example::

    http://localhost:8888/api/v2/yardstick/pods/5g6g3e02-155a-4847-a5f8-154f1b31db8c


METHOD: DELETE

Delete openrc file
Example::

    http://localhost:8888/api/v2/yardstick/pods/5g6g3e02-155a-4847-a5f8-154f1b31db8c


/api/v2/yardstick/images/action

Description: This API is used to do some work related to Yardstick VM images. For Euphrates, it supports:

1. Load Yardstick VM images;
2. Get image's information;
3. Delete images.

Which API to call will depend on the parameters.


METHOD: POST


Load VM images
Example::

    {
        'action': 'load_images'
    }


METHOD: GET

Get image information
Example::

    http://localhost:8888/api/v2/yardstick/images/5g6g3e02-155a-4847-a5f8-154f1b31db8c


METHOD: DELETE

Delete images
Example::

    http://localhost:8888/api/v2/yardstick/images/5g6g3e02-155a-4847-a5f8-154f1b31db8c


/api/v2/yardstick/tasks/action

Description: This API is used to do some work related to yardstick tasks. For Euphrates, it supports:

1. Create a Yardstick task;
2. run a Yardstick task;
3. Add a test case to a task;
4. Add a test suite to a task;
5. Get a tasks' information;
6. Delete a task.

Which API to call will depend on the parameters.


METHOD: POST


Create a Yardstick task
Example::

    {
        'action': 'create_task',
            'args': {
                'name': 'task1',
                'project_id': project_id
            }
    }


METHOD: PUT


Run a task
Example::

    {
        'action': 'run'
    }


METHOD: PUT


Add a test case to a task
Example::

    {
        'action': 'add_case',
        'args': {
            'case_name': 'opnfv_yardstick_tc002',
            'case_content': case_content
        }
    }


METHOD: PUT


Add a test suite to a task
Example::

    {
        'action': 'add_suite',
        'args': {
            'suite_name': 'opnfv_smoke',
            'suite_content': suite_content
        }
    }


METHOD: GET

Get a task's information
Example::

    http://localhost:8888/api/v2/yardstick/tasks/5g6g3e02-155a-4847-a5f8-154f1b31db8c


METHOD: DELETE

Delete a task
Example::
    http://localhost:8888/api/v2/yardstick/tasks/5g6g3e02-155a-4847-a5f8-154f1b31db8c


/api/v2/yardstick/testcases/action

Description: This API is used to do some work related to yardstick testcases. For Euphrates, it supports:

1. Upload a test case;
2. Get all released test cases' information;
3. Get a certain released test case's information;
4. Delete a test case.

Which API to call will depend on the parameters.


METHOD: POST


Upload a test case
Example::

    {
        'action': 'upload_case',
        'args': {
            'file': file
        }
    }


METHOD: GET


Get all released test cases' information
Example::

    http://localhost:8888/api/v2/yardstick/testcases


METHOD: GET


Get a certain released test case's information
Example::

    http://localhost:8888/api/v2/yardstick/testcases/opnfv_yardstick_tc002


METHOD: DELETE


Delete a certain test case
Example::
    http://localhost:8888/api/v2/yardstick/testcases/opnfv_yardstick_tc002


/api/v2/yardstick/testsuites/action

Description: This API is used to do some work related to yardstick test suites. For Euphrates, it supports:

1. Create a test suite;
2. Get a certain test suite's information;
3. Get all test suites;
4. Delete a test case.

Which API to call will depend on the parameters.


METHOD: POST


Create a test suite
Example::

    {
        'action': 'create_sutie',
        'args': {
            'name': <suite_name>,
            'testcases': [
                'opnfv_yardstick_tc002'
            ]
        }
    }


METHOD: GET


Get a certain test suite's information
Example::

    http://localhost:8888/api/v2/yardstick/testsuites/<suite_name>


METHOD: GET


Get all test suite
Example::

    http://localhost:8888/api/v2/yardstick/testsuites


METHOD: DELETE


Delete a certain test suite
Example::

    http://localhost:8888/api/v2/yardstick/testsuites/<suite_name>


/api/v2/yardstick/projects/action

Description: This API is used to do some work related to yardstick test projects. For Euphrates, it supports:

1. Create a Yardstick project;
2. Get a certain project's information;
3. Get all projects;
4. Delete a project.

Which API to call will depend on the parameters.


METHOD: POST


Create a Yardstick project
Example::

    {
        'action': 'create_project',
        'args': {
            'name': 'project1'
        }
    }


METHOD: GET


Get a certain project's information
Example::

    http://localhost:8888/api/v2/yardstick/projects/<project_id>


METHOD: GET


Get all projects' information
Example::

    http://localhost:8888/api/v2/yardstick/projects


METHOD: DELETE


Delete a certain project
Example::

    http://localhost:8888/api/v2/yardstick/projects/<project_id>


/api/v2/yardstick/containers/action

Description: This API is used to do some work related to Docker containers. For Euphrates, it supports:

1. Create a Grafana Docker container;
2. Create an InfluxDB Docker container;
3. Get a certain container's information;
4. Delete a container.

Which API to call will depend on the parameters.


METHOD: POST


Create a Grafana Docker container
Example::

    {
        'action': 'create_grafana',
        'args': {
            'environment_id': <environment_id>
        }
    }


METHOD: POST


Create an InfluxDB Docker container
Example::

    {
        'action': 'create_influxdb',
        'args': {
            'environment_id': <environment_id>
        }
    }


METHOD: GET


Get a certain container's information
Example::

    http://localhost:8888/api/v2/yardstick/containers/<container_id>


METHOD: DELETE


Delete a certain container
Example::

    http://localhost:8888/api/v2/yardstick/containers/<container_id>