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

« back to all changes in this revision

Viewing changes to src/maasserver/tests/test_provisioning.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-04-04 14:47:13 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20120404144713-nk3xrg5jfa9ahdhh
Tags: 0.1+bzr415+dfsg-0ubuntu1
* debian/control: Update package descriptions; Suggests maas-dhcp for maas
  and add a maas-dhcp binary.
* Add maas-dhcp package to configure a DHCP server.
  - debian/maas-dhcp.config: Add to ask debconf questions about range,
    gateway, and domain.
  - debian/maas-dhcp.postinst: Handle update of config values.
  - debian/maas-dhcp.templates: Debconf questions.
* debian/po: Update for templates.
* Add message telling MAAS URL after installation.
  - debian/maas.templates: Add message.
  - debian/maas.postinst: Display message.
* debian/maas.config: Hide dbconfig-install question.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
__metaclass__ = type
12
12
__all__ = []
13
13
 
 
14
from abc import ABCMeta
14
15
from urlparse import parse_qs
15
16
from xmlrpclib import Fault
16
17
 
19
20
from maasserver.exceptions import MAASAPIException
20
21
from maasserver.models import (
21
22
    ARCHITECTURE,
 
23
    ARCHITECTURE_CHOICES,
22
24
    Config,
23
25
    Node,
24
26
    NODE_AFTER_COMMISSIONING_ACTION,
40
42
    POWER_TYPE,
41
43
    PSERV_FAULT,
42
44
    )
 
45
from provisioningserver.testing.factory import ProvisioningFakeFactory
 
46
from testtools.deferredruntest import AsynchronousDeferredRunTest
43
47
from testtools.testcase import ExpectedException
 
48
from twisted.internet.defer import inlineCallbacks
44
49
 
45
50
 
46
51
class ProvisioningTests:
47
52
    """Tests for the Provisioning API as maasserver sees it."""
48
53
 
49
 
    # Must be defined in concrete subclasses.
 
54
    __metaclass__ = ABCMeta
 
55
 
 
56
    # This must be set to the provisioning server API proxy to test against.
50
57
    papi = None
51
58
 
52
59
    def make_node_without_saving(self, arch=ARCHITECTURE.i386):
58
65
                NODE_AFTER_COMMISSIONING_ACTION.DEFAULT),
59
66
            architecture=arch)
60
67
 
61
 
    def make_papi_profile(self):
62
 
        """Create a new profile on the provisioning API."""
63
 
        # Kernel and initrd are irrelevant here, but must be real files
64
 
        # for Cobbler's benefit.  Cobbler may not be running locally, so
65
 
        # just feed it some filenames that it's sure to have (and won't
66
 
        # be allowed accidentally to overwrite).
67
 
        shared_name = factory.getRandomString()
68
 
        distro_name = 'distro-%s' % shared_name
69
 
        fake_initrd = '/etc/cobbler/settings'
70
 
        fake_kernel = '/etc/cobbler/version'
71
 
        distro = self.papi.add_distro(distro_name, fake_initrd, fake_kernel)
72
 
        profile_name = 'profile-%s' % shared_name
73
 
        return self.papi.add_profile(profile_name, distro)
74
 
 
75
68
    def test_name_arch_in_cobbler_style_converts_architecture_names(self):
76
69
        self.assertSequenceEqual(
77
70
            ['i386', 'i386', 'x86_64', 'x86_64'],
87
80
    def test_name_arch_in_cobbler_returns_unicode(self):
88
81
        self.assertIsInstance(name_arch_in_cobbler_style(b'amd64'), unicode)
89
82
 
 
83
    @inlineCallbacks
90
84
    def test_select_profile_for_node_ignores_previously_chosen_profile(self):
91
85
        node = factory.make_node(architecture='i386')
92
 
        self.papi.modify_nodes(
93
 
            {node.system_id: {'profile': self.make_papi_profile()}})
 
86
        profile = yield self.add_profile(self.papi)
 
87
        yield self.papi.modify_nodes({node.system_id: {'profile': profile}})
94
88
        self.assertEqual(
95
 
            'maas-precise-i386', select_profile_for_node(node, self.papi))
 
89
            'maas-precise-i386', select_profile_for_node(node))
96
90
 
97
91
    def test_select_profile_for_node_selects_Precise_and_right_arch(self):
98
92
        nodes = {
102
96
                'maas-precise-%s' % name_arch_in_cobbler_style(arch)
103
97
                for arch in nodes.keys()],
104
98
            [
105
 
                select_profile_for_node(node, self.papi)
 
99
                select_profile_for_node(node)
106
100
                for node in nodes.values()])
107
101
 
108
102
    def test_select_profile_for_node_converts_architecture_name(self):
109
103
        node = factory.make_node(architecture='amd64')
110
 
        profile = select_profile_for_node(node, self.papi)
 
104
        profile = select_profile_for_node(node)
111
105
        self.assertNotIn('amd64', profile)
112
106
        self.assertIn('x86_64', profile)
113
107
 
 
108
    def test_select_profile_for_node_works_for_commissioning(self):
 
109
        # A special profile is chosen for nodes in the commissioning
 
110
        # state.
 
111
        arch = ARCHITECTURE.i386
 
112
        node = factory.make_node(
 
113
            status=NODE_STATUS.COMMISSIONING, architecture=arch)
 
114
        profile = select_profile_for_node(node)
 
115
        self.assertEqual('maas-precise-%s-commissioning' % arch, profile)
 
116
 
114
117
    def test_provision_post_save_Node_create(self):
115
118
        # The handler for Node's post-save signal registers the node in
116
119
        # its current state with the provisioning server.
324
327
        self.assertIsNone(present_user_friendly_fault(Fault(9999, "!!!")))
325
328
 
326
329
 
327
 
class TestProvisioningWithFake(ProvisioningTests, TestCase):
 
330
class TestProvisioningWithFake(ProvisioningTests, ProvisioningFakeFactory,
 
331
                               TestCase):
328
332
    """Tests for the Provisioning API using a fake."""
329
333
 
 
334
    run_tests_with = AsynchronousDeferredRunTest.make_factory(timeout=5)
 
335
 
330
336
    def setUp(self):
331
337
        super(TestProvisioningWithFake, self).setUp()
332
338
        self.papi = provisioning.get_provisioning_api_proxy()