~rvb/maas/ephemeral-simplestreams

« back to all changes in this revision

Viewing changes to maastest/prepare.py

  • Committer: jtv at canonical
  • Date: 2013-11-14 07:53:12 UTC
  • mfrom: (27.1.2 check-error)
  • Revision ID: jtv@canonical.com-20131114075312-q5wlai32uq6nk6z6
[r=julian-edwards][author=jtv] Check for installation errors; make MAAS installation setup, not test; hold completed VM for dev debugging.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
__metaclass__ = type
15
15
__all__ = [
16
 
    'configure_maas',
17
 
    'create_maas_admin',
18
16
    'determine_vm_series',
19
17
    'determine_vm_architecture',
20
 
    'import_maas_images',
21
 
    'query_api_key',
 
18
    'set_up_maas',
22
19
    ]
23
20
 
24
21
import platform
33
30
    """Could not determine CPU architecture."""
34
31
 
35
32
 
 
33
# TODO: Move to utils or kvmfixture.
36
34
def determine_vm_architecture():
37
35
    """Figure out CPU architecture for the virtual machine that will run MAAS.
38
36
 
56
54
    return ubuntu_names.get(raw_arch, raw_arch)
57
55
 
58
56
 
 
57
# TODO: Move to utils or kvmfixture.
59
58
def determine_vm_series():
60
59
    """Figure out the Ubuntu release series to run MAAS on.
61
60
 
65
64
    return series
66
65
 
67
66
 
 
67
# Standard, non-interactive, "apt-get install" line.
 
68
APT_GET_INSTALL = [
 
69
    'sudo', 'DEBIAN_FRONTEND=noninteractive',
 
70
    'apt-get', 'install', '-y',
 
71
    ]
 
72
 
 
73
 
 
74
def install_packages(kvm_fixture, packages):
 
75
    """Install the given packages on the virtual machine."""
 
76
    kvm_fixture.run_command(APT_GET_INSTALL + list(packages), check_call=True)
 
77
 
 
78
 
 
79
def install_maas(kvm_fixture):
 
80
    """Install and configure MAAS in the virtual machine."""
 
81
    # Install the English language pack first.  If this is not done before
 
82
    # postgres is installed, on some systems it won't be able to set up its
 
83
    # main cluster.
 
84
    # TODO: Is there no better way to ensure this, e.g. through a dependency?
 
85
    install_packages(kvm_fixture, ['language-pack-en'])
 
86
    # Now we can install maas (which also installs postgres).
 
87
    install_packages(kvm_fixture, ['maas', 'maas-dhcp', 'maas-dns'])
 
88
 
 
89
 
68
90
def query_api_key(kvm_fixture, username):
69
91
    """Return the API key for the given MAAS user."""
70
92
    # The "apikey" command prints the user's API key to stdout.
111
133
    # TODO: Actually implement.
112
134
 
113
135
 
114
 
def configure_maas(kvm_fixture):
115
 
    """Configure the MAAS running inside the virtual machine.
116
 
 
117
 
    MAAS must already have been installed.  This function creates an admin user
118
 
    and imports boot images.
 
136
def set_up_maas(kvm_fixture):
 
137
    """Install and configure MAAS inside the virtual machine.
119
138
 
120
139
    :param kvm_fixture: `KVMFixture` that controls the virtual machine.
121
140
    :return: Username and API key for the MAAS admin user.
122
141
    """
 
142
    install_maas(kvm_fixture)
123
143
    admin_user, password = create_maas_admin(kvm_fixture)
124
144
    api_key = query_api_key(kvm_fixture, admin_user)
125
145
    import_maas_images(kvm_fixture, admin_user, api_key)
 
146
    return admin_user, api_key