Merge "Prohibit the importation of a list of libraries"
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / lib / test_get_server.py
1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 import unittest
10 import mock
11
12 from yardstick.benchmark.scenarios.lib.get_server import GetServer
13
14
15 class GetServerTestCase(unittest.TestCase):
16
17     @mock.patch('yardstick.common.openstack_utils.get_server_by_name')
18     @mock.patch('yardstick.common.openstack_utils.get_nova_client')
19     def test_get_server_with_name(self, mock_get_nova_client, mock_get_server_by_name):
20         scenario_cfg = {
21             'options': {
22                 'server_name': 'yardstick_server'
23             },
24             'output': 'status server'
25         }
26         obj = GetServer(scenario_cfg, {})
27         obj.run({})
28         self.assertTrue(mock_get_nova_client.called)
29         self.assertTrue(mock_get_server_by_name.called)
30
31     @mock.patch('yardstick.common.openstack_utils.get_nova_client')
32     def test_get_server_with_id(self, mock_get_nova_client):
33         scenario_cfg = {
34             'options': {
35                 'server_id': '1'
36             },
37             'output': 'status server'
38         }
39         mock_get_nova_client().servers.get.return_value = None
40         obj = GetServer(scenario_cfg, {})
41         obj.run({})
42         self.assertTrue(mock_get_nova_client.called)