~lutostag/ubuntu/trusty/maas/1.5.4+keystone

« back to all changes in this revision

Viewing changes to src/provisioningserver/tests/test_tasks.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2013-03-04 11:49:44 UTC
  • mto: This revision was merged to the branch mainline in revision 25.
  • Revision ID: package-import@ubuntu.com-20130304114944-azcvu9anlf8mizpa
Tags: upstream-1.3+bzr1452+dfsg
ImportĀ upstreamĀ versionĀ 1.3+bzr1452+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
from provisioningserver.tags import MissingCredentials
65
65
from provisioningserver.tasks import (
66
66
    add_new_dhcp_host_map,
67
 
    import_pxe_files,
 
67
    import_boot_images,
68
68
    Omshell,
69
69
    power_off,
70
70
    power_on,
534
534
 
535
535
class TestImportPxeFiles(PservTestCase):
536
536
 
537
 
    def test_import_pxe_files(self):
538
 
        recorder = self.patch(tasks, 'check_call', Mock())
539
 
        import_pxe_files()
540
 
        recorder.assert_called_once_with(['maas-import-pxe-files'], env=ANY)
541
 
        self.assertIsInstance(import_pxe_files, Task)
542
 
 
543
 
    def test_import_pxe_files_preserves_environment(self):
544
 
        recorder = self.patch(tasks, 'check_call', Mock())
545
 
        import_pxe_files()
546
 
        recorder.assert_called_once_with(
547
 
            ['maas-import-pxe-files'], env=os.environ)
548
 
 
549
 
    def test_import_pxe_files_sets_proxy(self):
 
537
    def make_archive_url(self, name=None):
 
538
        if name is None:
 
539
            name = factory.make_name('archive')
 
540
        return 'http://%s.example.com/%s' % (name, factory.make_name('path'))
 
541
 
 
542
    def test_import_boot_images(self):
 
543
        recorder = self.patch(tasks, 'check_call', Mock())
 
544
        import_boot_images()
 
545
        recorder.assert_called_once_with(
 
546
            ['sudo', '-n', '-E', 'maas-import-pxe-files'], env=ANY)
 
547
        self.assertIsInstance(import_boot_images, Task)
 
548
 
 
549
    def test_import_boot_images_preserves_environment(self):
 
550
        recorder = self.patch(tasks, 'check_call', Mock())
 
551
        import_boot_images()
 
552
        recorder.assert_called_once_with(
 
553
            ['sudo', '-n', '-E', 'maas-import-pxe-files'], env=os.environ)
 
554
 
 
555
    def test_import_boot_images_sets_proxy(self):
550
556
        recorder = self.patch(tasks, 'check_call', Mock())
551
557
        proxy = factory.getRandomString()
552
 
        import_pxe_files(http_proxy=proxy)
 
558
        import_boot_images(http_proxy=proxy)
553
559
        expected_env = dict(os.environ, http_proxy=proxy, https_proxy=proxy)
554
560
        recorder.assert_called_once_with(
555
 
            ['maas-import-pxe-files'], env=expected_env)
 
561
            ['sudo', '-n', '-E', 'maas-import-pxe-files'], env=expected_env)
 
562
 
 
563
    def test_import_boot_images_sets_archive_locations(self):
 
564
        self.patch(tasks, 'check_call')
 
565
        archives = {
 
566
            'main_archive': self.make_archive_url('main'),
 
567
            'ports_archive': self.make_archive_url('ports'),
 
568
            'cloud_images_archive': self.make_archive_url('cloud-images'),
 
569
        }
 
570
        expected_settings = {
 
571
            parameter.upper(): value
 
572
            for parameter, value in archives.items()}
 
573
        import_boot_images(**archives)
 
574
        env = tasks.check_call.call_args[1]['env']
 
575
        archive_settings = {
 
576
            variable: value
 
577
            for variable, value in env.iteritems()
 
578
                if variable.endswith('_ARCHIVE')}
 
579
        self.assertEqual(expected_settings, archive_settings)