run_tests.sh can be executed without Nailgun
Splitted client's tests into unit and integration. Little cleanup in run_tests.sh Added new options in run_tests.sh: -i|--integration-tests -I|--no-integration-tests -u|--unit-tests -U|--no-unit-tests Script executes run_cleanup() and prepare_env() (which are responsible for cloning and running nailgun) only when running integration tests. Closes-Bug: #1409726 Change-Id: I0685b7534b4a0684ffc932c7d24654548735c9b9
This commit is contained in:
@@ -69,6 +69,17 @@ class CliExectutionResult:
|
||||
class UnitTestCase(TestCase):
|
||||
"""Base test class which does not require nailgun server to run."""
|
||||
|
||||
def setUp(self):
|
||||
"""Mocks keystone authentication."""
|
||||
self.mauth_client_patcher = mock.patch(
|
||||
'fuelclient.client.auth_client')
|
||||
self.mauth_client_patcher.start()
|
||||
super(UnitTestCase, self).setUp()
|
||||
|
||||
def tearDown(self):
|
||||
super(UnitTestCase, self).tearDown()
|
||||
self.mauth_client_patcher.stop()
|
||||
|
||||
def execute(self, command):
|
||||
return main(command)
|
||||
|
||||
|
||||
0
fuelclient/tests/common/unit/__init__.py
Normal file
0
fuelclient/tests/common/unit/__init__.py
Normal file
0
fuelclient/tests/v1/__init__.py
Normal file
0
fuelclient/tests/v1/__init__.py
Normal file
0
fuelclient/tests/v1/integration/__init__.py
Normal file
0
fuelclient/tests/v1/integration/__init__.py
Normal file
@@ -14,14 +14,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import os
|
||||
import urllib2
|
||||
|
||||
from mock import Mock
|
||||
from mock import patch
|
||||
|
||||
from fuelclient import fuelclient_settings
|
||||
from fuelclient.tests import base
|
||||
|
||||
|
||||
@@ -339,77 +333,3 @@ class TestDeployChanges(base.BaseTestCase):
|
||||
add_node = "--env-id=1 node set --node 1 --role=controller"
|
||||
deploy_changes = "deploy-changes --env 1"
|
||||
self.run_cli_commands((env_create, add_node, deploy_changes))
|
||||
|
||||
|
||||
class TestAuthentication(base.UnitTestCase):
|
||||
|
||||
def validate_credentials_response(self,
|
||||
args,
|
||||
username=None,
|
||||
password=None,
|
||||
tenant_name=None):
|
||||
conf = fuelclient_settings.get_settings()
|
||||
|
||||
self.assertEqual(args['username'], username)
|
||||
self.assertEqual(args['password'], password)
|
||||
self.assertEqual(args['tenant_name'], tenant_name)
|
||||
pr = urllib2.urlparse.urlparse(args['auth_url'])
|
||||
self.assertEqual(conf.SERVER_ADDRESS, pr.hostname)
|
||||
self.assertEqual(int(conf.LISTEN_PORT), int(pr.port))
|
||||
self.assertEqual('/keystone/v2.0', pr.path)
|
||||
|
||||
@patch('fuelclient.client.requests')
|
||||
@patch('fuelclient.client.auth_client')
|
||||
def test_credentials(self, mkeystone_cli, mrequests):
|
||||
mkeystone_cli.return_value = Mock(auth_token='')
|
||||
mrequests.get_request.return_value = Mock(status_code=200)
|
||||
self.execute(
|
||||
['fuel', '--user=a', '--password=b', 'node'])
|
||||
self.validate_credentials_response(
|
||||
mkeystone_cli.Client.call_args[1],
|
||||
username='a',
|
||||
password='b',
|
||||
tenant_name='admin'
|
||||
)
|
||||
self.execute(
|
||||
['fuel', '--user=a', '--password', 'b', 'node'])
|
||||
self.validate_credentials_response(
|
||||
mkeystone_cli.Client.call_args[1],
|
||||
username='a',
|
||||
password='b',
|
||||
tenant_name='admin'
|
||||
)
|
||||
self.execute(
|
||||
['fuel', '--user=a', '--password=b', '--tenant=t', 'node'])
|
||||
self.validate_credentials_response(
|
||||
mkeystone_cli.Client.call_args[1],
|
||||
username='a',
|
||||
password='b',
|
||||
tenant_name='t'
|
||||
)
|
||||
self.execute(
|
||||
['fuel', '--user', 'a', '--password', 'b', '--tenant', 't',
|
||||
'node'])
|
||||
self.validate_credentials_response(
|
||||
mkeystone_cli.Client.call_args[1],
|
||||
username='a',
|
||||
password='b',
|
||||
tenant_name='t'
|
||||
)
|
||||
self.execute(
|
||||
['fuel', 'node', '--user=a', '--password=b', '--tenant=t'])
|
||||
self.validate_credentials_response(
|
||||
mkeystone_cli.Client.call_args[1],
|
||||
username='a',
|
||||
password='b',
|
||||
tenant_name='t'
|
||||
)
|
||||
self.execute(
|
||||
['fuel', 'node', '--user', 'a', '--password', 'b',
|
||||
'--tenant', 't'])
|
||||
self.validate_credentials_response(
|
||||
mkeystone_cli.Client.call_args[1],
|
||||
username='a',
|
||||
password='b',
|
||||
tenant_name='t'
|
||||
)
|
||||
0
fuelclient/tests/v1/unit/__init__.py
Normal file
0
fuelclient/tests/v1/unit/__init__.py
Normal file
96
fuelclient/tests/v1/unit/test_authentication.py
Normal file
96
fuelclient/tests/v1/unit/test_authentication.py
Normal file
@@ -0,0 +1,96 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright 2013-2014 Mirantis, Inc.
|
||||
#
|
||||
# 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.
|
||||
|
||||
from mock import Mock
|
||||
from mock import patch
|
||||
import urllib2
|
||||
|
||||
from fuelclient import fuelclient_settings
|
||||
from fuelclient.tests import base
|
||||
|
||||
|
||||
class TestAuthentication(base.UnitTestCase):
|
||||
|
||||
def validate_credentials_response(self,
|
||||
args,
|
||||
username=None,
|
||||
password=None,
|
||||
tenant_name=None):
|
||||
conf = fuelclient_settings.get_settings()
|
||||
|
||||
self.assertEqual(args['username'], username)
|
||||
self.assertEqual(args['password'], password)
|
||||
self.assertEqual(args['tenant_name'], tenant_name)
|
||||
pr = urllib2.urlparse.urlparse(args['auth_url'])
|
||||
self.assertEqual(conf.SERVER_ADDRESS, pr.hostname)
|
||||
self.assertEqual(int(conf.LISTEN_PORT), int(pr.port))
|
||||
self.assertEqual('/keystone/v2.0', pr.path)
|
||||
|
||||
@patch('fuelclient.client.requests')
|
||||
@patch('fuelclient.client.auth_client')
|
||||
def test_credentials(self, mkeystone_cli, mrequests):
|
||||
mkeystone_cli.return_value = Mock(auth_token='')
|
||||
mrequests.get_request.return_value = Mock(status_code=200)
|
||||
self.execute(
|
||||
['fuel', '--user=a', '--password=b', 'node'])
|
||||
self.validate_credentials_response(
|
||||
mkeystone_cli.Client.call_args[1],
|
||||
username='a',
|
||||
password='b',
|
||||
tenant_name='admin'
|
||||
)
|
||||
self.execute(
|
||||
['fuel', '--user=a', '--password', 'b', 'node'])
|
||||
self.validate_credentials_response(
|
||||
mkeystone_cli.Client.call_args[1],
|
||||
username='a',
|
||||
password='b',
|
||||
tenant_name='admin'
|
||||
)
|
||||
self.execute(
|
||||
['fuel', '--user=a', '--password=b', '--tenant=t', 'node'])
|
||||
self.validate_credentials_response(
|
||||
mkeystone_cli.Client.call_args[1],
|
||||
username='a',
|
||||
password='b',
|
||||
tenant_name='t'
|
||||
)
|
||||
self.execute(
|
||||
['fuel', '--user', 'a', '--password', 'b', '--tenant', 't',
|
||||
'node'])
|
||||
self.validate_credentials_response(
|
||||
mkeystone_cli.Client.call_args[1],
|
||||
username='a',
|
||||
password='b',
|
||||
tenant_name='t'
|
||||
)
|
||||
self.execute(
|
||||
['fuel', 'node', '--user=a', '--password=b', '--tenant=t'])
|
||||
self.validate_credentials_response(
|
||||
mkeystone_cli.Client.call_args[1],
|
||||
username='a',
|
||||
password='b',
|
||||
tenant_name='t'
|
||||
)
|
||||
self.execute(
|
||||
['fuel', 'node', '--user', 'a', '--password', 'b',
|
||||
'--tenant', 't'])
|
||||
self.validate_credentials_response(
|
||||
mkeystone_cli.Client.call_args[1],
|
||||
username='a',
|
||||
password='b',
|
||||
tenant_name='t'
|
||||
)
|
||||
@@ -56,7 +56,7 @@ class TestGraphAction(base.UnitTestCase):
|
||||
|
||||
def test_download_all_tasks(self):
|
||||
with mock.patch('sys.stdout', new=io.StringIO()) as m_stdout:
|
||||
self.execute_wo_auth(
|
||||
self.execute(
|
||||
['fuel', 'graph', '--download', '--env', '1', '--download']
|
||||
)
|
||||
|
||||
@@ -67,7 +67,7 @@ class TestGraphAction(base.UnitTestCase):
|
||||
|
||||
def test_download_selected_tasks(self):
|
||||
with mock.patch('sys.stdout', new=io.StringIO()) as m_stdout:
|
||||
self.execute_wo_auth(
|
||||
self.execute(
|
||||
['fuel', 'graph', '--download', '--env', '1',
|
||||
'--tasks', 'task-a', 'task-b']
|
||||
)
|
||||
@@ -79,7 +79,7 @@ class TestGraphAction(base.UnitTestCase):
|
||||
|
||||
def test_download_with_skip(self):
|
||||
with mock.patch('sys.stdout', new=io.StringIO()) as m_stdout:
|
||||
self.execute_wo_auth(
|
||||
self.execute(
|
||||
['fuel', 'graph', '--download', '--env', '1',
|
||||
'--skip', 'sync-time', 'task-b']
|
||||
)
|
||||
@@ -91,7 +91,7 @@ class TestGraphAction(base.UnitTestCase):
|
||||
|
||||
def test_download_with_end_and_start(self):
|
||||
with mock.patch('sys.stdout', new=io.StringIO()) as m_stdout:
|
||||
self.execute_wo_auth(
|
||||
self.execute(
|
||||
['fuel', 'graph', '--download', '--env', '1',
|
||||
'--start', 'task-a', '--end', 'task-b']
|
||||
)
|
||||
@@ -107,7 +107,7 @@ class TestGraphAction(base.UnitTestCase):
|
||||
|
||||
def test_download_only_parents(self):
|
||||
with mock.patch('sys.stdout', new=io.StringIO()) as m_stdout:
|
||||
self.execute_wo_auth(
|
||||
self.execute(
|
||||
['fuel', 'graph', '--download', '--env', '1',
|
||||
'--parents-for', 'task-z']
|
||||
)
|
||||
@@ -117,7 +117,7 @@ class TestGraphAction(base.UnitTestCase):
|
||||
|
||||
def test_params_saved_in_dotfile(self):
|
||||
with mock.patch('sys.stdout', new=io.StringIO()) as m_stdout:
|
||||
self.execute_wo_auth(
|
||||
self.execute(
|
||||
['fuel', 'graph', '--download', '--env', '1',
|
||||
'--parents-for', 'task-z',
|
||||
'--skip', 'task-a']
|
||||
@@ -139,7 +139,7 @@ class TestGraphAction(base.UnitTestCase):
|
||||
m_exists.return_value = True
|
||||
m_open().__enter__().read.return_value = graph_data
|
||||
|
||||
self.execute_wo_auth(
|
||||
self.execute(
|
||||
['fuel', 'graph', '--render', 'graph.gv']
|
||||
)
|
||||
|
||||
@@ -150,7 +150,7 @@ class TestGraphAction(base.UnitTestCase):
|
||||
def test_render_no_file(self, m_exists):
|
||||
m_exists.return_value = False
|
||||
with self.assertRaises(SystemExit):
|
||||
self.execute_wo_auth(
|
||||
self.execute(
|
||||
['fuel', 'graph', '--render', 'graph.gv']
|
||||
)
|
||||
|
||||
@@ -166,7 +166,7 @@ class TestGraphAction(base.UnitTestCase):
|
||||
m_open().__enter__().read.return_value = graph_data
|
||||
self.m_full_path.return_value = output_dir
|
||||
|
||||
self.execute_wo_auth(
|
||||
self.execute(
|
||||
['fuel', 'graph', '--render', 'graph.gv', '--dir', output_dir]
|
||||
)
|
||||
|
||||
@@ -180,7 +180,7 @@ class TestGraphAction(base.UnitTestCase):
|
||||
graph_data = u'graph data'
|
||||
|
||||
with mock.patch('sys.stdin', new=io.StringIO(graph_data)):
|
||||
self.execute_wo_auth(
|
||||
self.execute(
|
||||
['fuel', 'graph', '--render', '-', ]
|
||||
)
|
||||
|
||||
@@ -196,7 +196,7 @@ class TestGraphAction(base.UnitTestCase):
|
||||
self.m_full_path.return_value = output_dir
|
||||
|
||||
with self.assertRaises(SystemExit):
|
||||
self.execute_wo_auth(
|
||||
self.execute(
|
||||
['fuel', 'graph', '--render', 'graph.gv', '--dir', output_dir]
|
||||
)
|
||||
m_access.assert_called_once_with(output_dir, os.W_OK)
|
||||
@@ -28,14 +28,14 @@ class TestNotificationsActions(base.UnitTestCase):
|
||||
response_mock = Mock(status_code=201)
|
||||
mrequests.post.return_value = response_mock
|
||||
|
||||
self.execute_wo_auth(
|
||||
self.execute(
|
||||
['fuel', 'notifications', '--send', 'test message'])
|
||||
self.assertEqual(mrequests.post.call_count, 1)
|
||||
request = json.loads(mrequests.post.call_args[1]['data'])
|
||||
self.assertEqual('test message', request['message'])
|
||||
self.assertEqual('done', request['topic'])
|
||||
|
||||
self.execute_wo_auth(
|
||||
self.execute(
|
||||
['fuel', 'notify', '-m', 'test message 2'])
|
||||
self.assertEqual(mrequests.post.call_count, 2)
|
||||
request = json.loads(mrequests.post.call_args[1]['data'])
|
||||
@@ -46,7 +46,7 @@ class TestNotificationsActions(base.UnitTestCase):
|
||||
response_mock = Mock(status_code=201)
|
||||
mrequests.post.return_value = response_mock
|
||||
|
||||
self.execute_wo_auth(
|
||||
self.execute(
|
||||
['fuel', 'notifications', '--send', 'test error',
|
||||
'--topic', 'error'])
|
||||
self.assertEqual(mrequests.post.call_count, 1)
|
||||
@@ -54,7 +54,7 @@ class TestNotificationsActions(base.UnitTestCase):
|
||||
self.assertEqual('test error', request['message'])
|
||||
self.assertEqual('error', request['topic'])
|
||||
|
||||
self.execute_wo_auth(
|
||||
self.execute(
|
||||
['fuel', 'notify', '-m', 'test error 2', '--topic', 'error'])
|
||||
self.assertEqual(mrequests.post.call_count, 2)
|
||||
request = json.loads(mrequests.post.call_args[1]['data'])
|
||||
@@ -67,14 +67,14 @@ class TestNotificationsActions(base.UnitTestCase):
|
||||
|
||||
self.assertRaises(
|
||||
SystemExit,
|
||||
self.execute_wo_auth,
|
||||
self.execute,
|
||||
['fuel', 'notifications', '--send']
|
||||
)
|
||||
self.assertEqual(mrequests.post.call_count, 0)
|
||||
|
||||
self.assertRaises(
|
||||
SystemExit,
|
||||
self.execute_wo_auth,
|
||||
self.execute,
|
||||
['fuel', 'notify', '-m']
|
||||
)
|
||||
self.assertEqual(mrequests.post.call_count, 0)
|
||||
@@ -85,7 +85,7 @@ class TestNotificationsActions(base.UnitTestCase):
|
||||
|
||||
self.assertRaises(
|
||||
SystemExit,
|
||||
self.execute_wo_auth,
|
||||
self.execute,
|
||||
['fuel', 'notifications', '--send', 'test message',
|
||||
'--topic', 'x']
|
||||
)
|
||||
@@ -93,7 +93,7 @@ class TestNotificationsActions(base.UnitTestCase):
|
||||
|
||||
self.assertRaises(
|
||||
SystemExit,
|
||||
self.execute_wo_auth,
|
||||
self.execute,
|
||||
['fuel', 'notify', '-m', 'test message', '--topic', 'x']
|
||||
)
|
||||
self.assertEqual(mrequests.post.call_count, 0)
|
||||
@@ -116,7 +116,7 @@ class TestNotificationsActions(base.UnitTestCase):
|
||||
mrequests.get.side_effect = [m1, m2]
|
||||
|
||||
mrequests.put.return_value = Mock(status_code=200)
|
||||
self.execute_wo_auth(
|
||||
self.execute(
|
||||
['fuel', 'notifications', '-r', '1'])
|
||||
|
||||
self.assertEqual(mrequests.get.call_count, 1)
|
||||
@@ -130,7 +130,7 @@ class TestNotificationsActions(base.UnitTestCase):
|
||||
|
||||
mrequests.get.side_effect = [m1, m2]
|
||||
|
||||
self.execute_wo_auth(
|
||||
self.execute(
|
||||
['fuel', 'notifications', '-r', '1', '2'])
|
||||
|
||||
self.assertEqual(mrequests.get.call_count, 3)
|
||||
@@ -161,7 +161,7 @@ class TestNotificationsActions(base.UnitTestCase):
|
||||
mrequests.get.return_value = m
|
||||
|
||||
mrequests.put.return_value = Mock(status_code=200)
|
||||
self.execute_wo_auth(
|
||||
self.execute(
|
||||
['fuel', 'notifications', '-r', '*'])
|
||||
|
||||
self.assertEqual(mrequests.get.call_count, 1)
|
||||
@@ -192,7 +192,7 @@ class TestNotificationsActions(base.UnitTestCase):
|
||||
mrequests.get.return_value = m
|
||||
|
||||
mrequests.put.return_value = Mock(status_code=200)
|
||||
self.execute_wo_auth(['fuel', 'notifications'])
|
||||
self.execute(['fuel', 'notifications'])
|
||||
|
||||
self.assertEqual(mrequests.get.call_count, 1)
|
||||
notifications = mformat_table.call_args[0][0]
|
||||
@@ -219,7 +219,7 @@ class TestNotificationsActions(base.UnitTestCase):
|
||||
mrequests.get.return_value = m
|
||||
|
||||
mrequests.put.return_value = Mock(status_code=200)
|
||||
self.execute_wo_auth(['fuel', 'notifications', '-a'])
|
||||
self.execute(['fuel', 'notifications', '-a'])
|
||||
|
||||
self.assertEqual(mrequests.get.call_count, 1)
|
||||
notifications = mformat_table.call_args[0][0]
|
||||
0
fuelclient/tests/v2/__init__.py
Normal file
0
fuelclient/tests/v2/__init__.py
Normal file
0
fuelclient/tests/v2/integration/__init__.py
Normal file
0
fuelclient/tests/v2/integration/__init__.py
Normal file
0
fuelclient/tests/v2/unit/__init__.py
Normal file
0
fuelclient/tests/v2/unit/__init__.py
Normal file
0
fuelclient/tests/v2/unit/cli/__init__.py
Normal file
0
fuelclient/tests/v2/unit/cli/__init__.py
Normal file
@@ -44,12 +44,12 @@ class BaseCLITest(base.UnitTestCase):
|
||||
def tearDown(self):
|
||||
self._get_client_patcher.stop()
|
||||
|
||||
def exec_v2_command(self, command=''):
|
||||
def exec_command(self, command=''):
|
||||
"""Executes fuelclient with the specified arguments."""
|
||||
|
||||
return main_mod.main(argv=command.split())
|
||||
|
||||
def exec_v2_command_interactive(self, commands):
|
||||
def exec_command_interactive(self, commands):
|
||||
"""Executes specified commands in one sesstion of interactive mode
|
||||
|
||||
Starts Fuel Client's interactive console and passes
|
||||
@@ -62,12 +62,12 @@ class BaseCLITest(base.UnitTestCase):
|
||||
"""
|
||||
with mock.patch.object(sys, 'stdin') as m_stdin:
|
||||
m_stdin.readline.side_effect = commands
|
||||
self.exec_v2_command()
|
||||
self.exec_command()
|
||||
|
||||
@mock.patch('cliff.commandmanager.CommandManager.find_command')
|
||||
def test_command_non_interactive(self, m_find_command):
|
||||
args = ['help']
|
||||
self.exec_v2_command(*args)
|
||||
self.exec_command(*args)
|
||||
m_find_command.assert_called_once_with(args)
|
||||
|
||||
@mock.patch.object(sys, 'stderr')
|
||||
@@ -79,7 +79,7 @@ class BaseCLITest(base.UnitTestCase):
|
||||
m_run.side_effect = error.FuelClientException(error_msg)
|
||||
|
||||
self.assertRaises(SystemExit,
|
||||
self.exec_v2_command,
|
||||
self.exec_command,
|
||||
'some command --fail True')
|
||||
m_stderr.write.assert_called_once_with(expected_output)
|
||||
|
||||
@@ -87,5 +87,5 @@ class BaseCLITest(base.UnitTestCase):
|
||||
def test_command_interactive(self, m_find_command):
|
||||
commands = ['quit']
|
||||
|
||||
self.exec_v2_command_interactive(commands)
|
||||
self.exec_command_interactive(commands)
|
||||
m_find_command.assert_called_once_with(commands)
|
||||
@@ -16,30 +16,30 @@
|
||||
|
||||
import mock
|
||||
|
||||
from fuelclient.tests.cli import test_v2_engine
|
||||
from fuelclient.tests.v2.unit.cli import test_engine
|
||||
from fuelclient.v1 import environment
|
||||
|
||||
|
||||
class TestEnvCommand(test_v2_engine.BaseCLITest):
|
||||
class TestEnvCommand(test_engine.BaseCLITest):
|
||||
"""Tests for fuel2 env * commands."""
|
||||
|
||||
def test_env_list(self):
|
||||
args = 'env list'
|
||||
self.exec_v2_command(args)
|
||||
self.exec_command(args)
|
||||
|
||||
self.m_get_client.assert_called_once_with('environment', mock.ANY)
|
||||
self.m_client.get_all.assert_called_once_with()
|
||||
|
||||
def test_env_show(self):
|
||||
args = 'env show 42'
|
||||
self.exec_v2_command(args)
|
||||
self.exec_command(args)
|
||||
|
||||
self.m_get_client.assert_called_once_with('environment', mock.ANY)
|
||||
self.m_client.get_by_id.assert_called_once_with(42)
|
||||
|
||||
def test_env_create(self):
|
||||
args = 'env create -r 1 -n neutron -nst gre env42'
|
||||
self.exec_v2_command(args)
|
||||
self.exec_command(args)
|
||||
|
||||
self.m_get_client.assert_called_once_with('environment', mock.ANY)
|
||||
|
||||
@@ -51,21 +51,21 @@ class TestEnvCommand(test_v2_engine.BaseCLITest):
|
||||
|
||||
def test_env_delete(self):
|
||||
args = 'env delete 42'
|
||||
self.exec_v2_command(args)
|
||||
self.exec_command(args)
|
||||
|
||||
self.m_get_client.assert_called_once_with('environment', mock.ANY)
|
||||
self.m_client.delete_by_id.assert_called_once_with(42)
|
||||
|
||||
def test_env_deploy(self):
|
||||
args = 'env deploy 42'
|
||||
self.exec_v2_command(args)
|
||||
self.exec_command(args)
|
||||
|
||||
self.m_get_client.assert_called_once_with('environment', mock.ANY)
|
||||
self.m_client.deploy_changes.assert_called_once_with(42)
|
||||
|
||||
def test_env_add_nodes(self):
|
||||
args = 'env add nodes -e 42 -n 24,25 -r compute,cinder'
|
||||
self.exec_v2_command(args)
|
||||
self.exec_command(args)
|
||||
|
||||
self.m_get_client.assert_called_once_with('environment', mock.ANY)
|
||||
self.m_client.add_nodes.assert_called_once_with(environment_id=42,
|
||||
@@ -78,7 +78,7 @@ class TestEnvCommand(test_v2_engine.BaseCLITest):
|
||||
environment.EnvironmentClient._updatable_attributes
|
||||
|
||||
args = 'env update -n test_name 42'
|
||||
self.exec_v2_command(args)
|
||||
self.exec_command(args)
|
||||
|
||||
self.m_get_client.assert_called_once_with('environment', mock.ANY)
|
||||
self.m_client.update.assert_called_once_with(environment_id=42,
|
||||
@@ -86,7 +86,7 @@ class TestEnvCommand(test_v2_engine.BaseCLITest):
|
||||
|
||||
def test_env_upgrade(self):
|
||||
args = 'env upgrade 10 15'
|
||||
self.exec_v2_command(args)
|
||||
self.exec_command(args)
|
||||
|
||||
self.m_get_client.assert_called_once_with('environment', mock.ANY)
|
||||
self.m_client.upgrade.assert_called_once_with(10, 15)
|
||||
@@ -16,15 +16,15 @@
|
||||
|
||||
import mock
|
||||
|
||||
from fuelclient.tests.cli import test_v2_engine
|
||||
from fuelclient.tests.v2.unit.cli import test_engine
|
||||
|
||||
|
||||
class TestNodeCommand(test_v2_engine.BaseCLITest):
|
||||
class TestNodeCommand(test_engine.BaseCLITest):
|
||||
"""Tests for fuel2 node * commands."""
|
||||
|
||||
def test_node_list(self):
|
||||
args = 'node list'
|
||||
self.exec_v2_command(args)
|
||||
self.exec_command(args)
|
||||
|
||||
self.m_get_client.assert_called_once_with('node', mock.ANY)
|
||||
self.m_client.get_all.assert_called_once_with(environment_id=None)
|
||||
@@ -33,7 +33,7 @@ class TestNodeCommand(test_v2_engine.BaseCLITest):
|
||||
env_id = 42
|
||||
args = 'node list --env {env}'.format(env=env_id)
|
||||
|
||||
self.exec_v2_command(args)
|
||||
self.exec_command(args)
|
||||
|
||||
self.m_get_client.assert_called_once_with('node', mock.ANY)
|
||||
self.m_client.get_all.assert_called_once_with(environment_id=env_id)
|
||||
@@ -42,7 +42,7 @@ class TestNodeCommand(test_v2_engine.BaseCLITest):
|
||||
node_id = 42
|
||||
args = 'node show {node_id}'.format(node_id=node_id)
|
||||
|
||||
self.exec_v2_command(args)
|
||||
self.exec_command(args)
|
||||
|
||||
self.m_get_client.assert_called_once_with('node', mock.ANY)
|
||||
self.m_client.get_by_id.assert_called_once_with(node_id)
|
||||
@@ -16,14 +16,14 @@
|
||||
|
||||
import mock
|
||||
|
||||
from fuelclient.tests.cli import test_v2_engine
|
||||
from fuelclient.tests.v2.unit.cli import test_engine
|
||||
|
||||
|
||||
class TestTaskCommand(test_v2_engine.BaseCLITest):
|
||||
class TestTaskCommand(test_engine.BaseCLITest):
|
||||
|
||||
def test_task_list(self):
|
||||
args = 'task list'
|
||||
self.exec_v2_command(args)
|
||||
self.exec_command(args)
|
||||
|
||||
self.m_get_client.assert_called_once_with('task', mock.ANY)
|
||||
self.m_client.get_all.assert_called_once_with()
|
||||
@@ -32,7 +32,7 @@ class TestTaskCommand(test_v2_engine.BaseCLITest):
|
||||
task_id = 42
|
||||
args = 'task show {task_id}'.format(task_id=task_id)
|
||||
|
||||
self.exec_v2_command(args)
|
||||
self.exec_command(args)
|
||||
|
||||
self.m_get_client.assert_called_once_with('task', mock.ANY)
|
||||
self.m_client.get_by_id.assert_called_once_with(task_id)
|
||||
0
fuelclient/tests/v2/unit/lib/__init__.py
Normal file
0
fuelclient/tests/v2/unit/lib/__init__.py
Normal file
@@ -22,7 +22,7 @@ from fuelclient.cli import error
|
||||
from fuelclient.objects import base as base_object
|
||||
from fuelclient.objects import environment as env_object
|
||||
from fuelclient.objects import task as task_object
|
||||
from fuelclient.tests.lib import test_api
|
||||
from fuelclient.tests.v2.unit.lib import test_api
|
||||
|
||||
|
||||
class TestEnvFacade(test_api.BaseLibTest):
|
||||
@@ -17,7 +17,7 @@
|
||||
import requests_mock as rm
|
||||
|
||||
import fuelclient
|
||||
from fuelclient.tests.lib import test_api
|
||||
from fuelclient.tests.v2.unit.lib import test_api
|
||||
|
||||
|
||||
class TestNodeFacade(test_api.BaseLibTest):
|
||||
@@ -17,7 +17,7 @@
|
||||
import requests_mock as rm
|
||||
|
||||
import fuelclient
|
||||
from fuelclient.tests.lib import test_api
|
||||
from fuelclient.tests.v2.unit.lib import test_api
|
||||
|
||||
|
||||
class TestTaskFacade(test_api.BaseLibTest):
|
||||
185
run_tests.sh
185
run_tests.sh
@@ -39,79 +39,128 @@ TEST_WORKERS=${TEST_WORKERS:-0}
|
||||
# A POSIX variable
|
||||
OPTIND=1
|
||||
|
||||
|
||||
# Prints usage and exist
|
||||
usage() {
|
||||
echo "Usage: $0 [OPTIONS] [-- TESTR OPTIONS]"
|
||||
echo "Run python-fuelclient test suite"
|
||||
echo ""
|
||||
echo " -6 --py26 Run python-2.6 tests."
|
||||
echo " -7 --py27 Run python-2.7 tests."
|
||||
echo " If neither -6 nor -7 is specified, tests for both"
|
||||
echo " versions will be running."
|
||||
echo " -c --fuel-commit Checkout fuel-web to a specified commit. If not specified,"
|
||||
echo " \$FUEL_COMMIT or master will be used."
|
||||
echo " By default checks out to master."
|
||||
echo " -f --fetch-repo URI of a remote repo for fetching changes to fuel-web."
|
||||
echo " If not specified, \$FETCH_REPO or nothing will be used."
|
||||
echo " -h, --help Print this usage message and exit."
|
||||
echo " -n --no-clone Do not clone fuel-web repo and use existing"
|
||||
echo " one specified in \$FUEL_WEB_ROOT. Make sure it"
|
||||
echo " does not have pending changes."
|
||||
echo " -p --pep8 Runs only flake8 tests."
|
||||
echo " -P --no-pep8 Do not run flake8 tests automatically."
|
||||
echo " -r --fetch-refspec Refspec to fetch from the remore repo. This option"
|
||||
echo " requires -r or --fetch-refspec to be specified."
|
||||
echo " If not specified, \$FETCH_REFSPEC or nothing will be used."
|
||||
echo " -t --test Test to run. To run many tests, pass this flag multiple times."
|
||||
echo " Runs all tests, if not specified. "
|
||||
msg "Usage: $0 [OPTIONS] [-- TESTR OPTIONS]"
|
||||
msg "Run python-fuelclient test suite"
|
||||
msg ""
|
||||
msg " -6 --py26 Run python-2.6 tests."
|
||||
msg " -7 --py27 Run python-2.7 tests."
|
||||
msg " If neither -6 nor -7 is specified, tests for both"
|
||||
msg " versions will be running."
|
||||
msg " -c --fuel-commit Checkout fuel-web to a specified commit. If not specified,"
|
||||
msg " \$FUEL_COMMIT or master will be used."
|
||||
msg " By default checks out to master."
|
||||
msg " -f --fetch-repo URI of a remote repo for fetching changes to fuel-web."
|
||||
msg " If not specified, \$FETCH_REPO or nothing will be used."
|
||||
msg " -h, --help Print this usage message and exit."
|
||||
msg " -i --integration-tests Run only integration tests."
|
||||
msg " -I --no-integration-tests Don't run integration tests."
|
||||
msg " -n --no-clone Do not clone fuel-web repo and use existing"
|
||||
msg " one specified in \$FUEL_WEB_ROOT. Make sure it"
|
||||
msg " does not have pending changes."
|
||||
msg " -p --pep8 Runs only flake8 tests."
|
||||
msg " -P --no-pep8 Do not run flake8 tests automatically."
|
||||
msg " -r --fetch-refspec Refspec to fetch from the remore repo. This option"
|
||||
msg " requires -r or --fetch-refspec to be specified."
|
||||
msg " If not specified, \$FETCH_REFSPEC or nothing will be used."
|
||||
msg " -t --test Test to run. To run many tests, pass this flag multiple times."
|
||||
msg " Runs all tests, if not specified. "
|
||||
msg " -u --unit-tests Run only unit tests."
|
||||
msg " -U --no-unit-tests Don't run unit tests."
|
||||
msg " -V --client-version Which version of python-fuelclient should be tested, for example:"
|
||||
msg " ./run_tests.sh -V v1"
|
||||
msg " To test multiple versions, pass this flag multiple times."
|
||||
exit
|
||||
}
|
||||
|
||||
err() {
|
||||
printf "%s\n" "$1" >&2
|
||||
}
|
||||
|
||||
msg() {
|
||||
printf "%s\n" "$1"
|
||||
}
|
||||
|
||||
# Reads input options and sets appropriate parameters
|
||||
process_options() {
|
||||
# Read the options
|
||||
TEMP=$(getopt \
|
||||
-o 67hnpPc:f:r:t: \
|
||||
--long py26,py27,help,no-clone,no-pep8,pep8,fuel-commit:,fetch-repo:,fetch-refspec:,tests: \
|
||||
-o 67huUiInpPc:f:r:t:V: \
|
||||
--long py26,py27,help,integration-tests,no-integration-tests,no-pep8,pep8,unit-tests,no-unit-tests,no-clone,client-version:,fuel-commit:,fetch-repo:,fetch-refspec:,tests: \
|
||||
-n 'run_tests.sh' -- "$@")
|
||||
|
||||
eval set -- "$TEMP"
|
||||
|
||||
while true ; do
|
||||
case "$1" in
|
||||
-6|--py26) python_26=1; shift 1;;
|
||||
-7|--py27) python_27=1; shift 1;;
|
||||
-c|--fuel-commit) fuel_commit="$2"; shift 2;;
|
||||
-f|--fetch-repo) fetch_repo="$2"; shift 2;;
|
||||
-h|--help) usage; shift 1;;
|
||||
-n|--no-clone) do_clone=0; shift 1;;
|
||||
-p|--pep8) pep8_only=1; shift 1;;
|
||||
-P|--no-pep8) do_pep8=0; shift 1;;
|
||||
-r|--fetch-refspec) fetch_refspec="$2"; shift 2;;
|
||||
-t|--test) certain_tests+=("$2"); shift 2;;
|
||||
|
||||
-6|--py26) python_26=1; shift 1;;
|
||||
-7|--py27) python_27=1; shift 1;;
|
||||
-h|--help) usage; shift 1;;
|
||||
-f|--fetch-repo) fetch_repo="$2"; shift 2;;
|
||||
-r|--fetch-refspec) fetch_refspec="$2"; shift 2;;
|
||||
-c|--fuel-commit) fuel_commit="$2"; shift 2;;
|
||||
-n|--no-clone) do_clone=0; shift 1;;
|
||||
-t|--test) certain_tests+=("$2"); shift 2;;
|
||||
-p|--pep8) pep8_only=1; shift 1;;
|
||||
-P|--no-pep8) do_pep8=0; shift 1;;
|
||||
-i|--integration-tests) integration_tests=1; shift 1;;
|
||||
-I|--no-integration-tests) no_integration_tests=1; shift 1;;
|
||||
-u|--unit-tests) unit_tests=1; shift 1;;
|
||||
-U|--no-unit-tests) no_unit_tests=1; shift 1;;
|
||||
-V|--client-version) client_version+=("$2"); shift 2;;
|
||||
# All parameters and alien options will be passed to testr
|
||||
--) shift 1; testropts="$@";
|
||||
break;;
|
||||
*) >&2 echo "Internal error: got \"$1\" argument.";
|
||||
*) err "Internal error: got \"$1\" argument.";
|
||||
usage; exit 1
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z $fetch_repo ]] && [[ -n $fetch_refspec ]]; then
|
||||
>&2 echo "Error: --fetch-refspec option requires --fetch-repo to be specified."
|
||||
if [[ -z $fetch_repo && -n $fetch_refspec ]]; then
|
||||
err "--fetch-refspec option requires --fetch-repo to be specified."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $unit_tests -eq 0 && \
|
||||
$integration_tests -eq 0 && \
|
||||
${#certain_tests[@]} -eq 0 ]]; then
|
||||
|
||||
if [[ $no_unit_tests -ne 1 ]]; then
|
||||
unit_tests=1
|
||||
fi
|
||||
|
||||
if [[ $no_integration_tests -ne 1 ]]; then
|
||||
integration_tests=1
|
||||
fi
|
||||
|
||||
else
|
||||
do_pep8=0
|
||||
fi
|
||||
|
||||
# when no version specified, choose all of the versions available
|
||||
if [[ ${#client_version[@]} -eq 0 ]]; then
|
||||
client_version+=("common")
|
||||
for version in ${ROOT}/fuelclient/tests/v[0-9]; do
|
||||
client_version+=(`basename $version`)
|
||||
done
|
||||
fi
|
||||
|
||||
for version in ${client_version[@]}; do
|
||||
if [[ $unit_tests -eq 1 ]]; then
|
||||
certain_tests+=("${ROOT}/fuelclient/tests/${version}/unit/")
|
||||
fi
|
||||
if [[ $integration_tests -eq 1 ]]; then
|
||||
certain_tests+=("${ROOT}/fuelclient/tests/${version}/integration/")
|
||||
fi
|
||||
done
|
||||
|
||||
# Check that specified test file/dir exists. Fail otherwise.
|
||||
if [[ ${#certain_tests[@]} -ne 0 ]]; then
|
||||
for test in ${certain_tests[@]}; do
|
||||
local file_name=${test%:*}
|
||||
|
||||
if [[ ! -f $file_name ]] && [[ ! -d $file_name ]]; then
|
||||
>&2 echo "Error: Specified tests were not found."
|
||||
err "Specified tests were not found."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
@@ -171,7 +220,7 @@ run_pep8() {
|
||||
run_cleanup() {
|
||||
local config=$1
|
||||
|
||||
echo "Doing a clean up."
|
||||
msg "Doing a clean up."
|
||||
|
||||
kill_server
|
||||
|
||||
@@ -208,7 +257,7 @@ setup_db() {
|
||||
local config=$1
|
||||
local defaults=$2
|
||||
|
||||
echo "Setting up database."
|
||||
msg "Setting up database."
|
||||
|
||||
pushd $NAILGUN_ROOT > /dev/null
|
||||
NAILGUN_CONFIG=$config tox -evenv -- python manage.py syncdb > /dev/null
|
||||
@@ -293,7 +342,7 @@ run_server() {
|
||||
prepare_env() {
|
||||
local config=$1
|
||||
|
||||
echo "Preparing test environment."
|
||||
msg "Preparing test environment."
|
||||
obtain_nailgun || return 1
|
||||
|
||||
mkdir -p $ARTIFACTS
|
||||
@@ -303,7 +352,7 @@ prepare_env() {
|
||||
|
||||
server_log=$(mktemp /tmp/test_nailgun_cli_server.XXXX)
|
||||
run_server $server_log $config || \
|
||||
{ echo "Failed to start Nailgun"; return 1; }
|
||||
{ err "Failed to start Nailgun"; return 1; }
|
||||
}
|
||||
|
||||
|
||||
@@ -336,27 +385,27 @@ EOL
|
||||
# Clones Nailgun from git, pulls specified patch and
|
||||
# switches to the specified commit
|
||||
obtain_nailgun() {
|
||||
echo "Obtaining Nailgun with the revision $fuel_commit"
|
||||
err "Obtaining Nailgun with the revision $fuel_commit"
|
||||
|
||||
if [[ $do_clone -ne 0 ]]; then
|
||||
git clone $FUEL_WEB_REPO $FUEL_WEB_ROOT || \
|
||||
{ echo "Failed to clone Nailgun"; return 1; }
|
||||
{ err "Failed to clone Nailgun"; return 1; }
|
||||
fi
|
||||
|
||||
if [[ ! -d "$NAILGUN_ROOT" ]]; then
|
||||
echo "Error: Nailgun directory $NAILGUN_ROOT not found."
|
||||
err "Nailgun directory $NAILGUN_ROOT not found."
|
||||
exit 1
|
||||
fi
|
||||
pushd $NAILGUN_ROOT > /dev/null
|
||||
|
||||
if [[ -n $fetch_repo ]]; then
|
||||
echo "Fetching changes from $fetch_repo $fetch_refspec"
|
||||
err "Fetching changes from $fetch_repo $fetch_refspec"
|
||||
git fetch $fetch_repo $fetch_refspec || \
|
||||
{ echo "Failed to pull changes"; return 1; }
|
||||
{ err "Failed to pull changes"; return 1; }
|
||||
fi
|
||||
|
||||
git checkout $fuel_commit || \
|
||||
{ echo "Failed to checkout to $fuel_commit"; return 1; }
|
||||
{ err "Failed to checkout to $fuel_commit"; return 1; }
|
||||
|
||||
popd > /dev/null
|
||||
}
|
||||
@@ -364,16 +413,21 @@ obtain_nailgun() {
|
||||
|
||||
# Sets default values for parameters
|
||||
init_default_params() {
|
||||
python_26=0
|
||||
python_27=0
|
||||
certain_tests=()
|
||||
client_version=()
|
||||
do_clone=1
|
||||
do_pep8=1
|
||||
pep8_only=0
|
||||
fetch_repo=$FETCH_REPO
|
||||
fetch_refspec=$FETCH_REFSPEC
|
||||
fetch_repo=$FETCH_REPO
|
||||
fuel_commit=$FUEL_COMMIT
|
||||
certain_tests=""
|
||||
integration_tests=0
|
||||
no_integration_tests=0
|
||||
no_unit_tests=0
|
||||
pep8_only=0
|
||||
python_26=0
|
||||
python_27=0
|
||||
testropts="--with-timer --timer-warning=10 --timer-ok=2 --timer-top-n=10"
|
||||
unit_tests=0
|
||||
}
|
||||
|
||||
|
||||
@@ -386,25 +440,28 @@ run() {
|
||||
run_cleanup $config
|
||||
|
||||
if [[ $do_pep8 -eq 1 ]]; then
|
||||
echo "Starting PEP8 tests..." >&2
|
||||
err "Starting PEP8 tests..."
|
||||
run_pep8 || pep8_ret=$?
|
||||
|
||||
[[ $pep8_ret -ne 0 ]] && echo "Failed tests: pep8" >&2
|
||||
[[ $pep8_ret -ne 0 ]] && err "Failed tests: pep8"
|
||||
[[ $pep8_only -eq 1 ]] && exit $pep8_ret
|
||||
fi
|
||||
|
||||
prepare_env $config
|
||||
echo "Starting python-fuelclient tests..." >&2
|
||||
if [[ "${certain_tests[@]}" == *"integration"* ]]; then
|
||||
prepare_env $config
|
||||
fi
|
||||
|
||||
err "Starting python-fuelclient tests..."
|
||||
run_cli_tests $config || cli_ret=$?
|
||||
[[ $cli_ret -ne 0 ]] && echo "Failed tests: cli_tests" >&2
|
||||
[[ $cli_ret -ne 0 ]] && err "Failed tests: cli_tests"
|
||||
|
||||
run_cleanup $config
|
||||
|
||||
if [[ $pep8_ret -ne 0 || $cli_ret -ne 0 ]]; then
|
||||
echo "Testing python-fuelclient failed."
|
||||
err "Testing python-fuelclient failed."
|
||||
exit 1
|
||||
else
|
||||
echo "Testing python-fuelclient succeeded."
|
||||
err "Testing python-fuelclient succeeded."
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user