aboutsummaryrefslogtreecommitdiffstats
path: root/samples/dummy-no-context.yaml
blob: e4ace44c2882c4ae0bad3068f2d8cf2a68569108 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
##############################################################################
# Copyright (c) 2017 Huawei Technologies Co.,Ltd 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
##############################################################################
---
# Sample benchmark task config file

schema: "yardstick:task:0.1"

scenarios:
-
  type: Dummy
  name: Dummy
  runner:
    type: Duration
    duration: 5
    interval: 1
ghlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* 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 */ }
#!/usr/bin/env python
#
# jose.lausuch@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 logging
import unittest
import os

import mock

from functest.cli.commands import cli_os
from functest.utils.constants import CONST


class CliOpenStackTesting(unittest.TestCase):

    def setUp(self):
        self.endpoint_ip = 'test_ip'
        self.os_auth_url = 'http://test_ip:test_port/v2.0'
        self.installer_type = 'test_installer_type'
        self.installer_ip = 'test_installer_ip'
        self.openstack_creds = 'test_openstack_creds'
        self.dir_repo_functest = 'test_dir_repo_functest'
        self.snapshot_file = 'test_snapshot_file'
        self.cli_os = cli_os.CliOpenStack()

    def test_ping_endpoint_default(self):
        self.cli_os.os_auth_url = self.os_auth_url
        self.cli_os.endpoint_ip = self.endpoint_ip
        with mock.patch('functest.cli.commands.cli_os.os.system',
                        return_value=0):
            self.assertEqual(self.cli_os.ping_endpoint(), 0)

    @mock.patch('functest.cli.commands.cli_os.exit', side_effect=Exception)
    @mock.patch('functest.cli.commands.cli_os.click.echo')
    def test_ping_endpoint_missing_auth_url(self, mock_click_echo,
                                            mock_exit):
        with self.assertRaises(Exception):
            self.cli_os.os_auth_url = None
            self.cli_os.ping_endpoint()
            mock_click_echo.assert_called_once_with("Source the OpenStack "
                                                    "credentials first '. "
                                                    "$creds'")

    @mock.patch('functest.cli.commands.cli_os.exit')
    @mock.patch('functest.cli.commands.cli_os.click.echo')
    def test_ping_endpoint_os_system_fails(self, mock_click_echo,
                                           mock_exit):
        self.cli_os.os_auth_url = self.os_auth_url
        self.cli_os.endpoint_ip = self.endpoint_ip
        with mock.patch('functest.cli.commands.cli_os.os.system',
                        return_value=1):
            self.cli_os.ping_endpoint()
            mock_click_echo.assert_called_once_with("Cannot talk to the "
                                                    "endpoint %s\n" %
                                                    self.endpoint_ip)
            mock_exit.assert_called_once_with(0)

    @mock.patch('functest.cli.commands.cli_os.ft_utils.execute_command')
    @mock.patch('functest.cli.commands.cli_os.os.path.isfile',
                return_value=False)
    @mock.patch('functest.cli.commands.cli_os.click.echo')
    def test_fetch_credentials_default(self, mock_click_echo,
                                       mock_os_path,
                                       mock_ftutils_execute):
        CONST.__setattr__('INSTALLER_TYPE', self.installer_type)
        CONST.__setattr__('INSTALLER_IP', self.installer_ip)
        cmd = ("%s/releng/utils/fetch_os_creds.sh -d %s -i %s -a %s"
               % (CONST.__getattribute__('dir_repos'),
                  self.openstack_creds,
                  self.installer_type,
                  self.installer_ip))
        self.cli_os.openstack_creds = self.openstack_creds
        self.cli_os.fetch_credentials()
        mock_click_echo.assert_called_once_with("Fetching credentials from "
                                                "installer node '%s' with "
                                                "IP=%s.." %
                                                (self.installer_type,
                                                 self.installer_ip))
        mock_ftutils_execute.assert_called_once_with(cmd, verbose=False)

    @mock.patch('functest.cli.commands.cli_os.ft_utils.execute_command')
    @mock.patch('functest.cli.commands.cli_os.os.path.isfile',
                return_value=False)
    @mock.patch('functest.cli.commands.cli_os.click.echo')
    def test_fetch_credentials_missing_installer_type(self, mock_click_echo,
                                                      mock_os_path,
                                                      mock_ftutils_execute):
        CONST.__setattr__('INSTALLER_TYPE', None)
        CONST.__setattr__('INSTALLER_IP', self.installer_ip)
        cmd = ("%s/releng/utils/fetch_os_creds.sh -d %s -i %s -a %s"
               % (CONST.__getattribute__('dir_repos'),
                  self.openstack_creds,
                  None,
                  self.installer_ip))
        self.cli_os.openstack_creds = self.openstack_creds
        self.cli_os.fetch_credentials()
        mock_click_echo.assert_any_call("The environment variable "
                                        "'INSTALLER_TYPE' is not"
                                        "defined. Please export it")
        mock_click_echo.assert_any_call("Fetching credentials from "
                                        "installer node '%s' with "
                                        "IP=%s.." %
                                        (None,
                                         self.installer_ip))
        mock_ftutils_execute.assert_called_once_with(cmd, verbose=False)

    @mock.patch('functest.cli.commands.cli_os.ft_utils.execute_command')
    @mock.patch('functest.cli.commands.cli_os.os.path.isfile',
                return_value=False)
    @mock.patch('functest.cli.commands.cli_os.click.echo')
    def test_fetch_credentials_missing_installer_ip(self, mock_click_echo,
                                                    mock_os_path,
                                                    mock_ftutils_execute):
        installer_type = self.installer_type
        installer_ip = None
        CONST.__setattr__('INSTALLER_TYPE', installer_type)
        CONST.__setattr__('INSTALLER_IP', installer_ip)
        cmd = ("%s/releng/utils/fetch_os_creds.sh -d %s -i %s -a %s"
               % (CONST.__getattribute__('dir_repos'),
                  self.openstack_creds,
                  installer_type,
                  installer_ip))
        self.cli_os.openstack_creds = self.openstack_creds
        self.cli_os.fetch_credentials()
        mock_click_echo.assert_any_call("The environment variable "
                                        "'INSTALLER_IP' is not"
                                        "defined. Please export it")
        mock_click_echo.assert_any_call("Fetching credentials from "
                                        "installer node '%s' with "
                                        "IP=%s.." %
                                        (installer_type,
                                         installer_ip))
        mock_ftutils_execute.assert_called_once_with(cmd, verbose=False)

    @mock.patch('functest.cli.commands.cli_os.ft_utils.execute_command')
    def test_check(self, mock_ftutils_execute):
        with mock.patch.object(self.cli_os, 'ping_endpoint'):
            CONST.__setattr__('dir_repo_functest', self.dir_repo_functest)
            cmd = os.path.join(CONST.__getattribute__('dir_repo_functest'),
                               "functest/ci/check_os.sh")
            self.cli_os.check()
            mock_ftutils_execute.assert_called_once_with(cmd, verbose=False)

    @mock.patch('functest.cli.commands.cli_os.os.path.isfile',
                return_value=False)
    @mock.patch('functest.cli.commands.cli_os.click.echo')
    def test_snapshot_create(self, mock_click_echo, mock_os_path):
        with mock.patch.object(self.cli_os, 'ping_endpoint'), \
                mock.patch('functest.cli.commands.cli_os.os_snapshot.main') \
                as mock_os_snapshot:
            self.cli_os.snapshot_create()
            mock_click_echo.assert_called_once_with("Generating Openstack "
                                                    "snapshot...")
            self.assertTrue(mock_os_snapshot.called)

    @mock.patch('functest.cli.commands.cli_os.os.path.isfile',
                return_value=True)
    @mock.patch('functest.cli.commands.cli_os.click.echo')
    def test_snapshot_create_overwrite(self, mock_click_echo, mock_os_path):
        with mock.patch('__builtin__.raw_input', return_value="y") \
                as mock_raw_input, \
                mock.patch.object(self.cli_os, 'ping_endpoint'), \
                mock.patch('functest.cli.commands.cli_os.os_snapshot.main') \
                as mock_os_snapshot:
            self.cli_os.snapshot_create()
            mock_click_echo.assert_called_once_with("Generating Openstack "
                                                    "snapshot...")
            mock_raw_input.assert_any_call("It seems there is already an "
                                           "OpenStack snapshot. Do you want "
                                           "to overwrite it with the current "
                                           "OpenStack status? [y|n]\n")
            self.assertTrue(mock_os_snapshot.called)

    @mock.patch('functest.cli.commands.cli_os.os.path.isfile',
                return_value=False)
    @mock.patch('functest.cli.commands.cli_os.click.echo')
    def test_snapshot_show_missing_snap(self, mock_click_echo, mock_os_path):
        self.cli_os.snapshot_show()
        mock_click_echo.assert_called_once_with("There is no OpenStack "
                                                "snapshot created. To create "
                                                "one run the command "
                                                "'functest openstack "
                                                "snapshot-create'")

    @mock.patch('functest.cli.commands.cli_os.os.path.isfile',
                return_value=True)
    @mock.patch('functest.cli.commands.cli_os.click.echo')
    def test_snapshot_show_default(self, mock_click_echo, mock_os_path):
        with mock.patch('__builtin__.open', mock.mock_open(read_data='0')) \
                as m:
            self.cli_os.snapshot_file = self.snapshot_file
            self.cli_os.snapshot_show()
            m.assert_called_once_with(self.snapshot_file, 'r')
            mock_click_echo.assert_called_once_with("\n0")

    @mock.patch('functest.cli.commands.cli_os.os.path.isfile',
                return_value=True)
    @mock.patch('functest.cli.commands.cli_os.click.echo')
    def test_clean(self, mock_click_echo, mock_os_path):
        with mock.patch.object(self.cli_os, 'ping_endpoint'), \
                mock.patch('functest.cli.commands.cli_os.os_clean.main') \
                as mock_os_clean:
            self.cli_os.clean()
            self.assertTrue(mock_os_clean.called)

    @mock.patch('functest.cli.commands.cli_os.os.path.isfile',
                return_value=False)
    @mock.patch('functest.cli.commands.cli_os.click.echo')
    def test_clean_missing_file(self, mock_click_echo, mock_os_path):
        with mock.patch.object(self.cli_os, 'ping_endpoint'):
            self.cli_os.clean()
            mock_click_echo.assert_called_once_with("Not possible to clean "
                                                    "OpenStack without a "
                                                    "snapshot. This could "
                                                    "cause problems. "
                                                    "Run first the command "
                                                    "'functest openstack "
                                                    "snapshot-create'")

    @mock.patch('functest.cli.commands.cli_os.click.echo')
    def test_show_credentials(self, mock_click_echo):
        key = 'OS_KEY'
        value = 'OS_VALUE'
        with mock.patch.dict(os.environ, {key: value}):
            self.cli_os.show_credentials()
            mock_click_echo.assert_any_call("{}={}".format(key, value))


if __name__ == "__main__":
    logging.disable(logging.CRITICAL)
    unittest.main(verbosity=2)