def setUp(self): self.juju = None if JUJU_USELIVE and JUJU_INSTALLED: self.juju = JujuState(_run('juju status').decode('ascii')) else: with open('test/juju-output/juju-status-multi-install.yaml') as f: self.juju = JujuState(f.read())
def test_some_services_ready(self): """ Verifies some ready services == not_ready list """ juju_state = JujuState(juju=MagicMock()) services = PropertyMock(return_value=self.services_some_ready) type(juju_state).services = services not_ready = [(a, b) for a, b in juju_state.get_agent_states() if b != 'started'] self.assertEqual(len(not_ready), 2) self.assertFalse(juju_state.all_agents_started())
def test_parse_state(): with open('test/juju-output/service-pending.out') as juju_file: with open('test/maas-output/twonodes.out') as maas_file: juju_state = JujuState(juju_file) maas_state = MaasState(json.load(maas_file)) update_machine_info(juju_state, maas_state) juju_machines = list(juju_state.machines()) assert ("node-4c49e73e-e8b8-11e2-ac16-5254002cb1d6" in juju_machines[0].instance_id) assert ("node-5fb74ba0-e8c1-11e2-b109-5254002cb1d6" in juju_machines[1].instance_id)
class JujuStateSingleTest(unittest.TestCase): "Read the 'juju status' yaml for single post-install" def setUp(self): with open('test/juju-output/juju-status-single-install.yaml') as f: self.juju = JujuState(f.read()) self.m_one = self.juju.machine("1") self.c_one = self.m_one.container("1/lxc/0") def test_ignore_bootstrap_node(self): "jujustate.machines() should not include #0" self.assertEqual(len(list(self.juju.machines())), 2) def test_services(self): "All services parsed correctly" expected = [ 'glance', 'juju-gui', 'keystone', 'mysql', 'nova-cloud-controller', 'nova-compute', 'openstack-dashboard', 'rabbitmq-server' ] actual = list(self.juju.services) actual_names = [s.service_name for s in actual] self.assertEqual(set(actual_names), set(expected)) def test_find_service(self): "Find a service based on charm name" cn = "juju-gui" s = self.juju.service(cn) self.assertEqual(cn, s.service_name) def test_bogus_service_returns_none(self): "return empty dictionary for nonexistent services" cn = "fake-bogus-charm" s = self.juju.service(cn) self.assertEqual({}, s.service) def test_two_machines_allocated(self): ml = self.juju.machines_allocated() self.assertEqual(2, len(ml)) def test_m_one_containers(self): cl = list(self.m_one.containers) self.assertEqual(7, len(cl)) self.assertEqual(self.c_one.agent_state, "started") def test_get_hardware(self): cpu_cores = self.m_one.hardware("cpu-cores") self.assertEqual(cpu_cores, '3') self.assertEqual(self.c_one.hardware("arch"), "amd64")
class JujuStateSingleTest(unittest.TestCase): "Read the 'juju status' yaml for single post-install" def setUp(self): with open('test/juju-output/juju-status-single-install.yaml') as f: self.juju = JujuState(f.read()) self.m_one = self.juju.machine("1") self.c_one = self.m_one.container("1/lxc/0") def test_ignore_bootstrap_node(self): "jujustate.machines() should not include #0" self.assertEqual(len(list(self.juju.machines())), 2) def test_services(self): "All services parsed correctly" expected = ['glance', 'juju-gui', 'keystone', 'mysql', 'nova-cloud-controller', 'nova-compute', 'openstack-dashboard', 'rabbitmq-server'] actual = list(self.juju.services) actual_names = [s.service_name for s in actual] self.assertEqual(set(actual_names), set(expected)) def test_find_service(self): "Find a service based on charm name" cn = "juju-gui" s = self.juju.service(cn) self.assertEqual(cn, s.service_name) def test_bogus_service_returns_none(self): "return empty dictionary for nonexistent services" cn = "fake-bogus-charm" s = self.juju.service(cn) self.assertEqual({}, s.service) def test_two_machines_allocated(self): ml = self.juju.machines_allocated() self.assertEqual(2, len(ml)) def test_m_one_containers(self): cl = list(self.m_one.containers) self.assertEqual(7, len(cl)) self.assertEqual(self.c_one.agent_state, "started") def test_get_hardware(self): cpu_cores = self.m_one.hardware("cpu-cores") self.assertEqual(cpu_cores, '3') self.assertEqual(self.c_one.hardware("arch"), "amd64")
def juju_state(): cfg = Config(CONFIGOBJ) if not len(cfg.juju_env['state-servers']) > 0: state_server = 'localhost:17070' else: state_server = cfg.juju_env['state-servers'][0] juju = JujuClient(url=path.join('wss://', state_server), password=cfg.juju_api_password) juju.login() return JujuState(juju)
class JujuStateSinglePredeployTest(unittest.TestCase): "Read the 'juju status' yaml for single pre-deploy" def setUp(self): with open('test/juju-output/juju-status-single-pre-deploy.yaml') as f: self.juju = JujuState(f.read()) def test_one_machine_allocated(self): ml = self.juju.machines_allocated() self.assertEqual(1, len(ml)) def test_no_services(self): sl = list(self.juju.services) self.assertEqual(0, len(sl)) def test_no_containers(self): m_one = self.juju.machines_allocated()[0] cl = list(m_one.containers) self.assertEqual(0, len(cl))
def authenticate_juju(self): if not len(self.config.juju_env['state-servers']) > 0: state_server = 'localhost:17070' else: state_server = self.config.juju_env['state-servers'][0] self.juju = JujuClient(url=path.join('wss://', state_server), password=self.config.juju_api_password) self.juju.login() self.juju_state = JujuState(self.juju) log.debug('Authenticated against juju api.')
def authenticate_juju(self): uuid = self.config.juju_env['environ-uuid'] if not len(self.config.juju_env['state-servers']) > 0: state_server = 'localhost:17070' else: state_server = self.config.juju_env['state-servers'][0] url = path.join('wss://', state_server, 'environment', uuid, 'api') self.juju = JujuClient(url=url, password=self.config.juju_api_password) self.juju.login() self.juju_state = JujuState(self.juju) log.debug('Authenticated against Juju: {}'.format(url))
def juju_state(): cfg = Config(CONFIGOBJ) uuid = cfg.juju_env['environ-uuid'] if not len(cfg.juju_env['state-servers']) > 0: state_server = 'localhost:17070' else: state_server = cfg.juju_env['state-servers'][0] url = path.join('wss://', state_server, 'environment', uuid, 'api') juju = JujuClient(url=url, password=cfg.juju_api_password) juju.login() return JujuState(juju)
class JujuStateMultiTest(unittest.TestCase): def setUp(self): self.juju = None if JUJU_USELIVE and JUJU_INSTALLED: self.juju = JujuState(_run('juju status').decode('ascii')) else: with open('test/juju-output/juju-status-multi-install.yaml') as f: self.juju = JujuState(f.read()) def test_verify_instance_id(self): """ Validate we have maas instance-ids Example instance-id: /MAAS/api/1.0/nodes/node-a59c35b4-bfed-11e3-b7a8-a0cec8006f97/ """ for m in self.juju.machines(): self.assertTrue('MAAS/api' in m.instance_id) def test_machine_dns_names(self): """ Are machine dns-names assigned """ for m in self.juju.machines(): self.assertTrue(m.dns_name) def test_machine_dns_names_host(self): """ Machines should have `maas` as the host in their dns-name """ for m in self.juju.machines(): self.assertTrue('maas' in m.dns_name) def test_container_dns_is_ip(self): """ Make sure dns-names are valid ip address """ for m in self.juju.machines(): for c in m.containers: self.assertTrue(ipaddress.ip_address(c.dns_name)) def test_container_lxc_instance_id(self): """ Container instance ids should have lxc defined """ for m in self.juju.machines(): for c in m.containers: self.assertTrue('lxc' in c.instance_id)
def setUp(self): self.conf = Config({}) self.mock_ui = MagicMock(name='ui') self.mock_log = MagicMock(name='log') self.mock_loop = MagicMock(name='loop') self.conf.setopt('headless', False) self.dc = Controller( ui=self.mock_ui, config=self.conf, loop=self.mock_loop) self.dc.initialize = MagicMock() self.dc.juju_state = JujuState(juju=MagicMock()) self.dc.juju_state.all_agents_started = MagicMock()
def setUp(self): with open('test/juju-output/juju-status-single-install.yaml') as f: self.juju = JujuState(f.read()) self.m_one = self.juju.machine("1") self.c_one = self.m_one.container("1/lxc/0")
def setUp(self): with open('test/juju-output/juju-status-single-pre-deploy.yaml') as f: self.juju = JujuState(f.read())