def test_duplicate_uid(self): jail = Jail(name='jail1', uid=11, master=self.system) jail2 = Jail(name='jail2', uid=12, master=self.system) with self.assertRaises(DuplicateJailUidError) as context_manager: jail2.uid = 11 self.assertEqual(context_manager.exception.message, "Can't attach `jail2` to `{master.name}`. A jail with uid `{jail.uid}` is" " already attached to `{master.name}`.".format(master=self.system, jail=jail))
def test_duplicate_hostname(self): jail = Jail(name='jail1', hostname='something.foo.bar', uid=11, master=self.system) jail2 = Jail(name='jail2', uid=12, master=self.system) with self.assertRaises(DuplicateJailHostnameError) as context_manager: jail2.hostname = 'something.foo.bar' self.assertEqual(context_manager.exception.message, "Can't attach `jail2` to `{master.name}`. Hostname `something.foo.bar`" " is already associated with `{master.name}`.".format(master=self.system, jail=jail))
def test_duplicate_name(self): assert Jail(name='jail1', uid=11, master=self.system) jail2 = Jail(name='jail3', uid=12, master=self.system) with self.assertRaises(DuplicateJailNameError) as context_manager: jail2.name = 'jail1' self.assertEqual(context_manager.exception.message, "Can't attach `{jail.name}` to `{master.name}`. Name `jail1` is already associated" " with `{master.name}`.".format(master=self.system, jail=jail2))
def test_hostname_wo_master(self): params = self.params.copy() system = Jail(**params) system.name = 'system2' system.uid = '11' system.hostname = 'system2.foo.bar' self.assertEqual(system.hostname, None, 'incorrect hostname') self.master.attach_jail(system) self.assertEqual(system.hostname, 'system2.foo.bar', 'incorrect hostname')
def test_invalid_uid(self): params = self.params.copy() params['uid'] = 0 with self.assertRaises(InvalidUIDError) as context_manager: self.system = Jail(**params) self.assertEqual(context_manager.exception.message, "`system` on `None`: uid must be an integer >= 0.")
def setUp(self): self.master = Master( name='system', hostname='system.foo.bar', ext_if=('re0', ['148.241.178.106/24', '1c02:4f8:0f0:14e6::/110']), int_if=('eth0', ['192.168.0.0/24', '1c02:4f8:0f0:14e6::0:0:1/110']), # lo_if=('lo0', ['127.0.0.1/24', '::1/110']), j_if=('re0', [ '10.0.2.0/24', '10.0.1.0/24', '1c02:4f8:0f0:14e6::2:0:1/110', '1c02:4f8:0f0:14e6::1:0:1/110' ]), jlo_if=('lo1', [ '127.0.2.0/24', '127.0.1.0/24', '::0:2:0:0/110', '::0:1:0:0/110' ]), ) self.handler = self.master.jail_handler self.jail1 = Jail( name='jail1', uid=12, hostname='jail1.foo.bar', master=self.master, auto_start=True, jail_class='web', )
def test_attached_alt_jail_type(self): class DummyMaster(Master): default_jail_type = 'D' params = self.params.copy() params['master'] = DummyMaster(**self.master_params) self.system = Jail(**params) self.assertEqual(self.system.jail_type, 'D', 'incorrect jail_type')
def test_mismatch_master_jail(self): jail = Jail(name='jail', uid=12) with self.assertRaises(MasterJailMismatchError) as context_manager: self.handler.get_jail_ext_if(jail) self.assertEqual( context_manager.exception.message, "`{jail}` is not attached to `{master}`.".format( master=self.master, jail=jail))
def test_no_hostname_w_master(self): params = self.params.copy() del params['hostname'] params['master'] = Master(**self.master_params) system = Jail(**params) self.assertEqual( system.hostname, '{}.{}'.format(params['name'], self.master_params['hostname']), 'incorrect hostname')
def test_bad_master(self): master_params = self.master_params.copy() del master_params['j_if'] del master_params['jlo_if'] params = self.params.copy() params['master'] = system = System(**master_params) with self.assertRaises(AttachNonMasterError) as context_manager: self.system = Jail(**params) self.assertEqual( context_manager.exception.message, "Can't attach `{params[name]}` to `{system.name}`." " `{system.name}` is not a master.".format(system=system, params=params))
def test_no_master_path(self): params = self.params.copy() del params['master'] self.system = Jail(**params) self.assertEqual(self.system.path, None, 'incorrect path')
def test_base_hostname_unset(self): params = self.params.copy() del params['hostname'] system = Jail(**params) self.assertEqual(system.base_hostname, None, 'incorrect base_hostname')
def test_is_attached_false(self): params = self.params.copy() system = Jail(**params) self.assertFalse(system.is_attached, 'incorrect is_attached value')
def test_handler_wo_master(self): params = self.params.copy() system = Jail(**params) self.assertEqual(system.handler, None, 'incorrect handler')
def test_no_hostname_wo_master(self): params = self.params.copy() del params['hostname'] system = Jail(**params) self.assertEqual(system.hostname, None, 'incorrect hostname')
def test_no_name(self): params = self.params.copy() del params['name'] with self.assertRaises(TypeError): Jail(**params)
def setUp(self): params = self.params.copy() self.master = params['master'] = Master(**self.master_params) self.system = Jail(**params)
def test_no_uid(self): params = self.params.copy() del params['uid'] with self.assertRaises(TypeError): self.system = Jail(**params)
def test_no_master_lo_if(self): params = self.params.copy() del params['master'] self.system = Jail(**params) self.assertEqual(self.system.lo_if, None, 'incorrect lo_if')
def test_no_auto_start(self): params = self.params.copy() del params['auto_start'] self.system = Jail(**params) self.assertEqual(self.system.auto_start, False, 'incorrect auto_start')
def test_unattached_jid(self): params = self.params.copy() del params['master'] self.system = Jail(**params) self.assertEqual(self.system.jid, None, 'incorrect jid')
def test_unattached_default_status(self): params = self.params.copy() del params['master'] self.system = Jail(**params) self.assertEqual(self.system.status, 'D', 'incorrect jail_type')