~blake-rouse/maas/is-importing-2.1

« back to all changes in this revision

Viewing changes to src/provisioningserver/drivers/hardware/tests/test_virsh.py

  • Committer: LaMont Jones
  • Date: 2016-12-07 12:59:10 UTC
  • mfrom: (5561 2.1)
  • mto: This revision was merged to the branch mainline in revision 5563.
  • Revision ID: lamont@canonical.com-20161207125910-fow7gg8v9bo0s1iq
merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
from lxml import etree
14
14
from maastesting.factory import factory
15
15
from maastesting.matchers import (
16
 
    MockAnyCall,
17
16
    MockCalledOnceWith,
18
 
    MockCalledWith,
19
17
    MockCallsMatch,
20
18
)
21
19
from maastesting.testcase import (
267
265
        # with some fake architectures.
268
266
        user = factory.make_name('user')
269
267
        system_id = factory.make_name('system_id')
270
 
        machines = [factory.make_name('machine') for _ in range(4)]
 
268
        machines = [factory.make_name('machine') for _ in range(5)]
271
269
        self.patch(virsh.VirshSSH, 'list').return_value = machines
272
270
        fake_arch = factory.make_name('arch')
273
271
        mock_arch = self.patch(virsh.VirshSSH, 'get_arch')
281
279
            virsh.VirshVMState.OFF,
282
280
            virsh.VirshVMState.OFF,
283
281
            virsh.VirshVMState.ON,
 
282
            virsh.VirshVMState.ON,
284
283
            ]
285
284
        mock_state = self.patch(virsh.VirshSSH, 'get_state')
286
285
        mock_state.side_effect = fake_states
310
309
        mock_poweroff = self.patch(virsh.VirshSSH, 'poweroff')
311
310
        mock_create_node = self.patch(virsh, 'create_node')
312
311
        mock_create_node.side_effect = asynchronous(
313
 
            lambda *args, **kwargs: system_id)
 
312
            lambda *args, **kwargs: None if machines[4] in args else system_id)
314
313
        mock_commission_node = self.patch(virsh, 'commission_node')
315
314
 
316
315
        # Patch login and logout so that we don't really contact
324
323
            SAMPLE_DUMPXML_2,
325
324
            SAMPLE_DUMPXML_3,
326
325
            SAMPLE_DUMPXML_4,
 
326
            SAMPLE_DUMPXML,
327
327
        ]
328
328
 
329
329
        mock_run = self.patch(virsh.VirshSSH, 'run')
339
339
        self.expectThat(
340
340
            mock_login, MockCalledOnceWith(poweraddr, fake_password))
341
341
 
342
 
        # The first and last machine should have poweroff called on it, as it
343
 
        # was initial in the on state.
344
 
        self.expectThat(mock_poweroff, MockAnyCall(machines[0]))
345
 
 
346
 
        self.expectThat(mock_poweroff, MockAnyCall(machines[3]))
347
 
 
348
342
        # Check that the create command had the correct parameters for
349
343
        # each machine.
350
344
        self.expectThat(
361
355
                call(
362
356
                    fake_macs[3], fake_arch, 'virsh', called_params[3],
363
357
                    domain, machines[3]),
364
 
            ))
 
358
                call(
 
359
                    fake_macs[4], fake_arch, 'virsh', called_params[4],
 
360
                    domain, machines[4]),
 
361
            ))
 
362
 
 
363
        # The first and last machine should have poweroff called on it, as it
 
364
        # was initial in the on state.
 
365
        self.expectThat(
 
366
            mock_poweroff, MockCallsMatch(
 
367
                call(machines[0]),
 
368
                call(machines[3]),
 
369
            ))
 
370
 
365
371
        self.assertThat(mock_logout, MockCalledOnceWith())
366
372
        self.expectThat(
367
 
            mock_commission_node,
368
 
            MockCalledWith(system_id, user))
 
373
            mock_commission_node, MockCallsMatch(
 
374
                call(system_id, user),
 
375
                call(system_id, user),
 
376
                call(system_id, user),
 
377
                call(system_id, user),
 
378
            ))
369
379
 
370
380
    @inlineCallbacks
371
381
    def test_probe_and_enlist_login_failure(self):