142
128
self.assertEqual(nodegroup_uuid, cache.cache.get('nodegroup_uuid'))
145
class TestPowerTasks(PservTestCase):
148
("celery", FixtureResource(CeleryFixture())),
151
def test_ether_wake_power_on_with_not_enough_template_args(self):
152
# In eager test mode the assertion is raised immediately rather
153
# than being stored in the AsyncResult, so we need to test for
154
# that instead of using result.get().
156
PowerActionFail, power_on.delay, "ether_wake")
158
def test_ether_wake_power_on(self):
159
result = power_on.delay(
160
"ether_wake", mac_address=arbitrary_mac)
161
self.assertTrue(result.successful())
163
def test_ether_wake_does_not_support_power_off(self):
165
PowerActionFail, power_off.delay,
166
"ether_wake", mac=arbitrary_mac)
169
131
class TestDHCPTasks(PservTestCase):
537
499
'//node', tag_nsmap=None, retry=True)
540
class TestImportBootImages(PservTestCase):
542
def make_archive_url(self, name=None):
544
name = factory.make_name('archive')
545
return 'http://%s.example.com/%s' % (name, factory.make_name('path'))
547
def patch_boot_resources_function(self):
548
"""Patch out `boot_resources.import_images`.
550
Returns the installed fake. After the fake has been called, but not
551
before, its `env` attribute will have a copy of the environment dict.
555
"""Fake function; records a copy of the environment."""
557
def __call__(self, *args, **kwargs):
559
self.env = os.environ.copy()
561
return self.patch(boot_resources, 'import_images', CaptureEnv())
563
def test_import_boot_images_integrates_with_boot_resources_function(self):
564
# If the config specifies no sources, nothing will be imported. But
565
# the task succeeds without errors.
566
fixture = self.useFixture(BootSourcesFixture([]))
567
self.patch(boot_resources, 'logger')
568
self.patch(boot_resources, 'locate_config').return_value = (
570
import_boot_images(sources=[])
571
self.assertIsInstance(import_boot_images, Task)
573
def test_import_boot_images_sets_GPGHOME(self):
574
home = self.make_dir()
575
self.patch(tasks, 'get_maas_user_gpghome').return_value = home
576
fake = self.patch_boot_resources_function()
577
import_boot_images(sources=[])
578
self.assertEqual(home, fake.env['GNUPGHOME'])
580
def test_import_boot_images_sets_proxy_if_given(self):
581
proxy = 'http://%s.example.com' % factory.make_name('proxy')
582
proxy_vars = ['http_proxy', 'https_proxy']
583
fake = self.patch_boot_resources_function()
584
import_boot_images(sources=[], http_proxy=proxy)
588
for var in proxy_vars
590
filter_dict(fake.env, proxy_vars))
592
def test_import_boot_images_leaves_proxy_unchanged_if_not_given(self):
593
proxy_vars = ['http_proxy', 'https_proxy']
594
fake = self.patch_boot_resources_function()
595
import_boot_images(sources=[])
596
self.assertEqual({}, filter_dict(fake.env, proxy_vars))
598
def test_import_boot_images_calls_callback(self):
599
self.patch_boot_resources_function()
600
mock_callback = Mock()
601
import_boot_images(sources=[], callback=mock_callback)
602
self.assertThat(mock_callback.delay, MockCalledOnceWith())
604
def test_import_boot_images_accepts_sources_parameter(self):
605
fake = self.patch(boot_resources, 'import_images')
608
'path': "http://example.com",
613
'subarches': ["generic"],
614
'labels': ["release"]
619
import_boot_images(sources=sources)
620
self.assertThat(fake, MockCalledOnceWith(sources))
623
502
class TestAddUCSM(PservTestCase):
625
504
def test_enlist_nodes_from_ucsm(self):