~ubuntu-branches/ubuntu/raring/maas/raring-updates

« 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: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2012 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Tests for Celery tasks."""
 
5
 
 
6
from __future__ import (
 
7
    absolute_import,
 
8
    print_function,
 
9
    unicode_literals,
 
10
    )
 
11
 
 
12
__metaclass__ = type
 
13
__all__ = []
 
14
 
 
15
import os
 
16
 
 
17
from maasserver.enum import ARCHITECTURE
 
18
from maastesting.celery import CeleryFixture
 
19
from maastesting.factory import factory
 
20
from maastesting.matchers import ContainsAll
 
21
from maastesting.testcase import TestCase
 
22
from provisioningserver.enum import POWER_TYPE
 
23
from provisioningserver.power.poweraction import PowerActionFail
 
24
from provisioningserver.tasks import (
 
25
    power_off,
 
26
    power_on,
 
27
    write_tftp_config_for_node,
 
28
    )
 
29
from testresources import FixtureResource
 
30
from testtools.matchers import FileContains
 
31
 
 
32
# An arbitrary MAC address.  Not using a properly random one here since
 
33
# we might accidentally affect real machines on the network.
 
34
arbitrary_mac = "AA:BB:CC:DD:EE:FF"
 
35
 
 
36
 
 
37
class TestPowerTasks(TestCase):
 
38
 
 
39
    resources = (
 
40
        ("celery", FixtureResource(CeleryFixture())),
 
41
        )
 
42
 
 
43
    def test_ether_wake_power_on_with_not_enough_template_args(self):
 
44
        # In eager test mode the assertion is raised immediately rather
 
45
        # than being stored in the AsyncResult, so we need to test for
 
46
        # that instead of using result.get().
 
47
        self.assertRaises(
 
48
            PowerActionFail, power_on.delay, POWER_TYPE.WAKE_ON_LAN)
 
49
 
 
50
    def test_ether_wake_power_on(self):
 
51
        result = power_on.delay(POWER_TYPE.WAKE_ON_LAN, mac=arbitrary_mac)
 
52
        self.assertTrue(result.successful())
 
53
 
 
54
    def test_ether_wake_does_not_support_power_off(self):
 
55
        self.assertRaises(
 
56
            PowerActionFail, power_off.delay,
 
57
            POWER_TYPE.WAKE_ON_LAN, mac=arbitrary_mac)
 
58
 
 
59
 
 
60
class TestTFTPTasks(TestCase):
 
61
 
 
62
    resources = (
 
63
        ("celery", FixtureResource(CeleryFixture())),
 
64
        )
 
65
 
 
66
    def test_write_tftp_config_for_node_writes_files(self):
 
67
        arch = ARCHITECTURE.i386
 
68
        mac = factory.getRandomMACAddress()
 
69
        mac2 = factory.getRandomMACAddress()
 
70
        tftproot = self.make_dir()
 
71
        kernel = factory.getRandomString()
 
72
        menutitle = factory.getRandomString()
 
73
        append = factory.getRandomString()
 
74
 
 
75
        result = write_tftp_config_for_node.delay(
 
76
            arch, (mac, mac2), tftproot=tftproot, menutitle=menutitle,
 
77
            kernelimage=kernel, append=append)
 
78
 
 
79
        self.assertTrue(result.successful(), result)
 
80
        expected_file1 = os.path.join(
 
81
            tftproot, 'maas', arch, "generic", "pxelinux.cfg",
 
82
            mac.replace(":", "-"))
 
83
        expected_file2 = os.path.join(
 
84
            tftproot, 'maas', arch, "generic", "pxelinux.cfg",
 
85
            mac2.replace(":", "-"))
 
86
        self.assertThat(
 
87
            expected_file1,
 
88
            FileContains(matcher=ContainsAll((kernel, menutitle, append))))
 
89
        self.assertThat(
 
90
            expected_file2,
 
91
            FileContains(matcher=ContainsAll((kernel, menutitle, append))))