def test_deb_convert_install(self, m_check_call): cplane_utils.CHARM_LIB_DIR = '.' cplane_utils.filename['jboss'] = 'test.txt' cplane_utils.deb_convert_install('jboss') m_check_call.assert_called_with( ['alien', '--scripts', '-d', '-i', 'test.txt']) @patch("cplane_utils.deb_convert_install") def test_install_oracle(self, m_deb_convert_install): cplane_utils.install_oracle() m_deb_convert_install.assert_called_with('oracle-xe') @patch("subprocess.check_call") @patch("cplane_utils.set_oracle_env") @patch("os.chdir") @patch("os.system") @patch("cplane_utils.oracle_configure_init") def test_configure_oracle(self, m_oracle_configure_init, m_system, m_chdir, m_set_oracle_env, m_check_call): cplane_utils.configure_oracle() m_check_call.assert_called_with(['chmod', '+x', 'oracle-xe']) @patch("commands.getoutput") def test_get_os_release(self, m_getoutput): cplane_utils.get_os_release() self.assertEqual(m_getoutput.call_args, call('lsb_release -r')) suite = unittest.TestLoader().loadTestsFromTestCase(CplaneUtilsTest) unittest.TextTestRunner(verbosity=2).run(suite)
#!/usr/bin/python from test_utils import CharmTestCase, unittest import cplane_context TO_PATCH = [ 'context', 'config', ] class CplaneContextTest(CharmTestCase): def setUp(self): super(CplaneContextTest, self).setUp(cplane_context, TO_PATCH) self.config.side_effect = self.test_config.get def tearDown(self): super(CplaneContextTest, self).tearDown() def test_get_overlay_network_type(self): self.test_config.set('overlay-network-type', 'gre') self.assertEquals(cplane_context.get_overlay_network_type(), 'gre') suite = unittest.TestLoader().loadTestsFromTestCase(CplaneContextTest) unittest.TextTestRunner(verbosity=2).run(suite)
def test_check_interface(self): # check for valid interface self.assertEqual(cplane_network.check_interface('lo'), True) # check for invalid interface self.assertEqual(cplane_network.check_interface('cplane'), False) @patch.object(cplane_network, 'ni') def test_get_int_config(self, m_ni): m_ni.interfaces.return_value = NI_OUTPUT m_ni.ifaddresses.return_value = NI_OUTPUT['ethX'] self.assertEqual(cplane_network.get_int_config('ethX'), NI_EXPECTED[ni.AF_INET]) @patch.object(cplane_network, 'ni') def test_get_int_config_no_int(self, m_ni): m_ni.interfaces.return_value = NI_OUTPUT with self.assertRaises(cplane_network.InterfaceConfigurationException): cplane_network.get_int_config('ethY') @patch.object(cplane_network, 'ni') def test_get_int_config_no_af(self, m_ni): m_ni.interfaces.return_value = NI_OUTPUT_NO_AF m_ni.ifaddresses.return_value = NI_OUTPUT_NO_AF['ethX'] with self.assertRaises(cplane_network.InterfaceConfigurationException): cplane_network.get_int_config('ethX') suite = unittest.TestLoader().loadTestsFromTestCase(CplaneNetworkTest) unittest.TextTestRunner(verbosity=2).run(suite)
self.test_config.set('l2-population', False) self.os_release.return_value = 'juno' ctxt_data = { 'overlay_network_type': 'gre', 'enable_dvr': False, 'vlan_ranges': 'physnet1:1000:2000', 'l2_population': False, 'l3_ha': True, 'debug': True, 'external_network': 'ext_net', 'verbose': True } napi_ctxt = cplane_context.NeutronCCContext() with patch.object(napi_ctxt, '_ensure_packages'): self.assertEquals(ctxt_data, napi_ctxt()) def test_neutroncc_context_manager(self): napi_ctxt = cplane_context.NeutronCCContext() self.assertEquals(napi_ctxt.network_manager, 'neutron') self.assertEquals(napi_ctxt.plugin, 'ovs') self.assertEquals(napi_ctxt.neutron_security_groups, True) suite = unittest.TestLoader().loadTestsFromTestCase(GeneralTest) unittest.TextTestRunner(verbosity=2).run(suite) suite = unittest.TestLoader().loadTestsFromTestCase(IdentityServiceContext) unittest.TextTestRunner(verbosity=2).run(suite) suite = unittest.TestLoader().loadTestsFromTestCase(NeutronCCContextTest) unittest.TextTestRunner(verbosity=2).run(suite)