aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_floating_ip.py
blob: 45a39eba268cab087d5b6b8e4d55c8435ab91353 (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
##############################################################################
# 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
##############################################################################
from oslo_utils import uuidutils
import unittest
import mock

from yardstick.common import openstack_utils
from yardstick.common import exceptions
from yardstick.benchmark.scenarios.lib import delete_floating_ip


class DeleteFloatingIpTestCase(unittest.TestCase):

    def setUp(self):
        self._mock_delete_floating_ip = mock.patch.object(
            openstack_utils, 'delete_floating_ip')
        self.mock_delete_floating_ip = self._mock_delete_floating_ip.start()
        self._mock_get_shade_client = mock.patch.object(
            openstack_utils, 'get_shade_client')
        self.mock_get_shade_client = self._mock_get_shade_client.start()
        self._mock_log = mock.patch.object(delete_floating_ip, 'LOG')
        self.mock_log = self._mock_log.start()
        self.args = {'options': {'floating_ip_id': uuidutils.generate_uuid()}}
        self.result = {}

        self.del_obj = delete_floating_ip.DeleteFloatingIp(
            self.args, mock.ANY)

        self.addCleanup(self._stop_mock)

    def _stop_mock(self):
        self._mock_delete_floating_ip.stop()
        self._mock_get_shade_client.stop()
        self._mock_log.stop()

    def test_run(self):
        self.mock_delete_floating_ip.return_value = True
        self.assertIsNone(self.del_obj.run(self.result))
        self.assertEqual({"delete_floating_ip": 1}, self.result)
        self.mock_log.info.assert_called_once_with(
            "Delete floating ip successful!")

    def test_run_fail(self):
        self.mock_delete_floating_ip.return_value = False
        with self.assertRaises(exceptions.ScenarioDeleteFloatingIPError):
            self.del_obj.run(self.result)
        self.assertEqual({"delete_floating_ip": 0}, self.result)
        self.mock_log.error.assert_called_once_with(
            "Delete floating ip failed!")