class MaasClientTest(unittest.TestCase):
    def setUp(self):
        self.c = MaasClient(AUTH)
        self.tag = 'a-test-tag-' + randomString()
        res = self.c.tag_new(self.tag)
        self.assertTrue(res)

    def tearDown(self):
        res = self.c.tag_delete(self.tag)
        self.assertTrue(res)

    def test_get_tags(self):
        self.assertTrue(self.tag in [t['name'] for t in self.c.tags])
class MaasClientZoneTest(unittest.TestCase):
    def setUp(self):
        self.c = MaasClient(AUTH)
        self.zone_name = 'testzone-' + randomString()
        res = self.c.zone_new(self.zone_name,
                              'zone created in unittest')
        self.assertTrue(res)

    def tearDown(self):
        res = self.c.zone_delete(self.zone_name)
        self.assertTrue(res)

    def test_get_zones(self):
        self.assertTrue(self.zone_name in [z['name'] for z in self.c.zones])
def poll_state():
    """ Polls current state of Juju and MAAS

    :returns: list of Machine() and the Juju state
    :rtype: tuple (JujuState(), MaasState())
    """
    # Capture Juju state
    cmd = utils.get_command_output('juju status',
                                   combine_output=False)
    if cmd['ret']:
        raise SystemExit("Error connecting to juju: stderr: {e}".format(
            e=cmd['stderr']))
    juju = JujuState(cmd['stdout'])

    maas = None
    if MULTI_SYSTEM:
        # Login to MAAS
        auth = MaasAuth()
        auth.get_api_key('root')
        # auth.login()

        # Load Client routines
        c = MaasClient(auth)

        # Capture Maas state
        maas = MaasState(c.nodes)
        c.tag_fpi(maas)
        c.nodes_accept_all()
        c.tag_name(maas)

    update_machine_info(juju, maas)
    return (juju, maas)
Beispiel #4
0
def poll_state():
    """ Polls current state of Juju and MAAS

    :returns: list of Machine() and the Juju state
    :rtype: tuple (JujuState(), MaasState())
    """
    # Capture Juju state
    (ret, juju_stdout,
     juju_stderr, _) = utils.get_command_output('juju status',
                                                combine_output=False)
    if ret:
        log.debug("Juju state unknown, will re-poll in "
                  "case bootstrap is taking a little longer to come up.")
        log.debug("Juju status output: {o} \n stderr: {e}".format(
            o=juju_stdout, e=juju_stderr))
        # Stub out a juju status for now
        juju = JujuState('environment: local\nmachines:')
    else:
        try:
            juju = JujuState(juju_stdout)
        except:
            log.exception("Ignoring exception in parsing juju state.")
            juju = JujuState('environment: local\nmachines:')

    maas = None
    if MULTI_SYSTEM:
        # Login to MAAS
        auth = MaasAuth()
        auth.get_api_key('root')
        # auth.login()

        # Load Client routines
        c = MaasClient(auth)

        # Capture Maas state
        maas = MaasState(c.nodes)
        c.tag_fpi(maas)
        c.nodes_accept_all()
        c.tag_name(maas)

    update_machine_info(juju, maas)
    return (juju, maas)
 def setUp(self):
     self.c = MaasClient(AUTH)
     self.zone_name = 'testzone-' + randomString()
     res = self.c.zone_new(self.zone_name,
                           'zone created in unittest')
     self.assertTrue(res)
 def setUp(self):
     self.c = MaasClient(AUTH)
     self.tag = 'a-test-tag-' + randomString()
     res = self.c.tag_new(self.tag)
     self.assertTrue(res)