File: test_migration.py

package info (click to toggle)
python-pypowervm 1.1.24%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 7,400 kB
  • sloc: python: 29,780; xml: 174; makefile: 14
file content (153 lines) | stat: -rw-r--r-- 7,266 bytes parent folder | download
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Copyright 2015, 2018 IBM Corp.
#
# All Rights Reserved.
#
#    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.

import mock
import testtools

import pypowervm.entities as ent
from pypowervm.tasks import migration as mig
import pypowervm.tests.tasks.util as u
import pypowervm.tests.test_fixtures as fx


class TestMigration(testtools.TestCase):
    """Unit Tests for Migration."""

    def setUp(self):
        super(TestMigration, self).setUp()
        self.adpt = self.useFixture(fx.AdapterFx()).adpt
        mock_resp = mock.MagicMock()
        mock_resp.entry = ent.Entry(
            {}, ent.Element('Dummy', self.adpt), self.adpt)
        self.adpt.read.return_value = mock_resp
        self.lpar_w = mock.MagicMock()
        self.lpar_w.adapter = self.adpt
        self.lpar_w.uuid = '1234'

    @mock.patch('pypowervm.wrappers.job.Job.run_job')
    def test_migration(self, mock_run_job):

        # Test simple call
        mock_run_job.side_effect = u.get_parm_checker(
            self, '1234', [(mig.TGT_MGD_SYS, 'abc')], exp_timeout=1800 * 4)
        mig.migrate_lpar(self.lpar_w, 'abc')
        self.adpt.read.assert_called_once_with('LogicalPartition', '1234',
                                               suffix_parm='Migrate',
                                               suffix_type='do')
        # Test all parms
        self.adpt.read.reset_mock()
        parm_list = [(mig.TGT_MGD_SYS, 'abc'),
                     (mig.TGT_RMT_HMC, 'host'),
                     (mig.TGT_RMT_HMC_USR, 'usr'),
                     (mig.DEST_MSP, '1.1.1.1,2.2.2.2'),
                     (mig.SRC_MSP, '3.3.3.3,4.4.4.4'),
                     (mig.SPP_ID, '5'),
                     (mig.OVS_OVERRIDE, '2'),
                     (mig.VLAN_BRIDGE_OVERRIDE, '2')]
        mapping_list = [(mig.VFC_MAPPINGS, ['1/1/1', '3/3/3//3']),
                        (mig.VSCSI_MAPPINGS, ['2/2/2']),
                        (mig.VLAN_MAPPINGS, ['001122334455/4',
                                             '001122334466/5/6 7'])]
        mock_run_job.side_effect = u.get_parm_checker(
            self, '1234', parm_list, exp_job_mappings=mapping_list,
            exp_timeout=1800 * 4)

        mig.migrate_lpar(self.lpar_w, 'abc',
                         tgt_mgmt_svr='host', tgt_mgmt_usr='usr',
                         virtual_fc_mappings=['1/1/1', '3/3/3//3'],
                         virtual_scsi_mappings=['2/2/2'],
                         vlan_mappings=['001122334455/4',
                                        '001122334466/5/6 7'],
                         dest_msp_name='1.1.1.1,2.2.2.2',
                         source_msp_name='3.3.3.3,4.4.4.4',
                         spp_id='5', sdn_override=True,
                         vlan_check_override=True)
        self.adpt.read.assert_called_once_with('LogicalPartition', '1234',
                                               suffix_parm='Migrate',
                                               suffix_type='do')
        # Test migrate with affinity flag
        self.adpt.read.reset_mock()
        parm_list = [(mig.TGT_MGD_SYS, 'abc'),
                     (mig.TGT_RMT_HMC, 'host'),
                     (mig.TGT_RMT_HMC_USR, 'usr'),
                     (mig.DEST_MSP, '1.1.1.1,2.2.2.2'),
                     (mig.SRC_MSP, '3.3.3.3,4.4.4.4'),
                     (mig.SPP_ID, '5'),
                     (mig.OVS_OVERRIDE, '2'),
                     (mig.VLAN_BRIDGE_OVERRIDE, '2'),
                     (mig.AFFINITY, 'true')]
        mapping_list = [(mig.VFC_MAPPINGS, ['1/1/1', '3/3/3//3']),
                        (mig.VSCSI_MAPPINGS, ['2/2/2']),
                        (mig.VLAN_MAPPINGS, ['001122334455/4',
                                             '001122334466/5/6 7'])]
        mock_run_job.side_effect = u.get_parm_checker(
            self, '1234', parm_list, exp_job_mappings=mapping_list,
            exp_timeout=1800 * 4)

        mig.migrate_lpar(self.lpar_w, 'abc',
                         tgt_mgmt_svr='host', tgt_mgmt_usr='usr',
                         virtual_fc_mappings=['1/1/1', '3/3/3//3'],
                         virtual_scsi_mappings=['2/2/2'],
                         vlan_mappings=['001122334455/4',
                                        '001122334466/5/6 7'],
                         dest_msp_name='1.1.1.1,2.2.2.2',
                         source_msp_name='3.3.3.3,4.4.4.4',
                         spp_id='5', sdn_override=True,
                         vlan_check_override=True,
                         check_affinity_score=True)
        self.adpt.read.assert_called_once_with('LogicalPartition', '1234',
                                               suffix_parm='Migrate',
                                               suffix_type='do')
        # Test simple validation call
        self.adpt.read.reset_mock()
        mock_run_job.side_effect = u.get_parm_checker(
            self, '1234', [(mig.TGT_MGD_SYS, 'abc')], exp_timeout=1800 * 4)
        mock_run_job.reset_mock()
        mig.migrate_lpar(self.lpar_w, 'abc', validate_only=True)
        self.adpt.read.assert_called_once_with('LogicalPartition', '1234',
                                               suffix_parm='MigrateValidate',
                                               suffix_type='do')

    @mock.patch('pypowervm.wrappers.job.Job.run_job')
    def test_migration_recover(self, mock_run_job):
        # Test simple call
        mig.migrate_recover(self.lpar_w)
        self.adpt.read.assert_called_once_with('LogicalPartition', '1234',
                                               suffix_parm='MigrateRecover',
                                               suffix_type='do')
        mock_run_job.assert_called_once_with(
            '1234', job_parms=[], timeout=1800)

        # Test simple call with force
        self.adpt.read.reset_mock()
        mock_run_job.reset_mock()
        mock_run_job.side_effect = u.get_parm_checker(
            self, '1234', [('Force', 'true')], exp_timeout=1800)
        mig.migrate_recover(self.lpar_w, force=True)

        self.adpt.read.assert_called_once_with('LogicalPartition', '1234',
                                               suffix_parm='MigrateRecover',
                                               suffix_type='do')

    @mock.patch('pypowervm.wrappers.job.Job.run_job')
    def test_migration_abort(self, mock_run_job):
        # Test simple call
        mig.migrate_abort(self.lpar_w)
        self.adpt.read.assert_called_once_with('LogicalPartition', '1234',
                                               suffix_parm='MigrateAbort',
                                               suffix_type='do')
        mock_run_job.assert_called_once_with(
            '1234', job_parms=None, timeout=1800)