~ubuntu-branches/ubuntu/precise/maas/precise

« back to all changes in this revision

Viewing changes to src/provisioningserver/testing/realcobbler.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-04-17 23:44:46 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20120417234446-y3212quny2x1gft8
Tags: 0.1+bzr482+dfsg-0ubuntu1
* New upstream release (Fixes LP: #981103)
* debian/maas.postinst:
  - Make sure rabbitmq and postgresql are started on upgrade (LP: #981282)
  - Handle upgrades from any lower than 0.1+bzr462+dfsg-0ubuntu1 to
    correctly re-generate passwords, and not have db sync/migrate issues
    as config has changed upstream.
  - Correctly set Passwords for PSERV, otherwise it won't set new passwords.
* Allow MAAS_DEFAULT_URL reconfiguration. (LP: #980970)
  - debian/maas.config: Add reconfigure validation to correctly allow it,
    and ask a question.
  - debian/maas.postinst: Reconfigure DEFAULT_MAAS_URL as well as cobbler
    server and next_server for PXE/Provisioning.
  - debian/maas.templates: Add debconf question and update info.
* Do not lose MAAS_DEFAULT_URL settings on upgrade (LP: #984309)
* debian/maas.postinst:
  - Set cobbler password in between quotes (LP: #984427)
  - Do not change permissions to maas.log (LP: #980915)
* no longer use maas-cloudimg2ephemeral, but rather use premade images 
  at http://maas.ubuntu.com

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
"""Set up test sessions against real Cobblers."""
5
5
 
6
6
from __future__ import (
 
7
    absolute_import,
7
8
    print_function,
8
9
    unicode_literals,
9
10
    )
16
17
from os import environ
17
18
from textwrap import dedent
18
19
from urlparse import urlparse
 
20
from unittest import skipIf
19
21
 
20
22
from provisioningserver.cobblerclient import CobblerSession
21
23
 
33
35
 
34
36
    env_var = 'PSERV_TEST_COBBLER_URL'
35
37
 
36
 
    help_text = dedent("""
 
38
    help_text_available = dedent("""\
37
39
        Set %s to the URL for a Cobbler instance to test against,
 
40
        e.g. http://username:password@example.com/cobbler_api.
 
41
        WARNING: this will modify your Cobbler database.
 
42
        """ % env_var)
 
43
 
 
44
    help_text_local = dedent("""\
 
45
        Set %s to the URL for a *local* Cobbler instance to test against,
38
46
        e.g. http://username:password@localhost/cobbler_api.
39
47
        WARNING: this will modify your Cobbler database.
40
 
        """.lstrip('\n') % env_var)
 
48
        """ % env_var)
41
49
 
42
50
    def __init__(self):
43
51
        self.url = environ.get(self.env_var)
46
54
            self.username = urlparts.username or 'cobbler'
47
55
            self.password = urlparts.password or ''
48
56
 
 
57
    @property
49
58
    def is_available(self):
50
 
        """Is a real Cobbler available for tests?
51
 
 
52
 
        Use this to disable real-Cobbler tests if no real Cobbler is
53
 
        available: annotate them with
54
 
 
55
 
        @testtools.skipIf(
56
 
            not real_cobbler.is_available(), RealCobbler.help_text)
57
 
        """
 
59
        """Is a real Cobbler available for tests?"""
58
60
        return self.url is not None
59
61
 
 
62
    @property
 
63
    def skip_unless_available(self):
 
64
        """Decorator to disable tests if no real Cobbler is available.
 
65
 
 
66
        Annotate tests like so::
 
67
 
 
68
          @real_cobbler.skip_unless_available
 
69
          def test_something_that_requires_a_real_cobbler(self):
 
70
              ...
 
71
 
 
72
        """
 
73
        return skipIf(not self.is_available, self.help_text_available)
 
74
 
 
75
    @property
 
76
    def is_local(self):
 
77
        """Is a real Cobbler installed locally available for tests?"""
 
78
        if self.is_available:
 
79
            hostname = urlparse(self.url).hostname
 
80
            return hostname == "localhost" or hostname.startswith("127.")
 
81
        else:
 
82
            return False
 
83
 
 
84
    @property
 
85
    def skip_unless_local(self):
 
86
        """Decorator to disable tests if no real *local* Cobbler is available.
 
87
 
 
88
        Annotate tests like so::
 
89
 
 
90
          @real_cobbler.skip_unless_local
 
91
          def test_something_that_requires_a_real_local_cobbler(self):
 
92
              ...
 
93
 
 
94
        """
 
95
        return skipIf(not self.is_local, self.help_text_local)
 
96
 
60
97
    def get_session(self):
61
98
        """Obtain a session on the real Cobbler.
62
99
 
63
100
        Returns None if no real Cobbler is available.
64
101
        """
65
 
        if self.is_available():
 
102
        if self.is_available:
66
103
            return CobblerSession(self.url, self.username, self.password)
67
104
        else:
68
105
            return None