Merge "Make Sample VNF hugepages size configurable"
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / lib / test_get_migrate_target_host.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_migrate_target_host import GetMigrateTargetHost
13
14 BASE = 'yardstick.benchmark.scenarios.lib.get_migrate_target_host'
15
16
17 class GetMigrateTargetHostTestCase(unittest.TestCase):
18
19     @mock.patch('{}.openstack_utils.get_nova_client'.format(BASE))
20     @mock.patch('{}.GetMigrateTargetHost._get_migrate_host'.format(BASE))
21     @mock.patch('{}.GetMigrateTargetHost._get_current_host_name'.format(BASE))
22     def test_get_migrate_target_host(self,
23                                      mock_get_current_host_name,
24                                      mock_get_migrate_host,
25                                      mock_get_nova_client):
26         obj = GetMigrateTargetHost({}, {})
27         obj.run({})
28         mock_get_nova_client.assert_called_once()
29         mock_get_current_host_name.assert_called_once()
30         mock_get_migrate_host.assert_called_once()
31
32     @mock.patch('{}.openstack_utils.get_nova_client'.format(BASE))
33     def test_get_migrate_host(self, mock_get_nova_client):
34         class A(object):
35             def __init__(self, service):
36                 self.service = service
37                 self.host = 'host4'
38
39         mock_get_nova_client().hosts.list_all.return_value = [A('compute')]
40         obj = GetMigrateTargetHost({}, {})
41         host = obj._get_migrate_host('host5')
42         mock_get_nova_client.assert_called()
43         self.assertEqual(host, 'host4')