def setUp(self): # Create a system that consists of a cli tasklet # running inside a VM, that is running within a colony. self.cli = RaCliProc(name='test.cli') self.colony = RaColony(name='test.colony') self.cluster = RaCluster(name='test.cluster') self.manifest = RaManifest(northbound_listing=None, persist_dir_name='test') self.assertEqual(self.manifest.netconf_trace, NetconfTrace.AUTO) # Put the CLI tasklet into a proc self.cli_proc = RaProc(name='test.proc.cli') self.cli_proc.add_component(self.cli) # Add the CLI process to the VM self.vm = RaVm(name='test.vm') self.vm.add_component(self.cli_proc) self.cluster.add_component(self.vm) self.colony.add_component(self.cluster) self.manifest.add_component(self.colony)
class TestManifest(unittest.TestCase): def setUp(self): # Create a system that consists of a cli tasklet # running inside a VM, that is running within a colony. self.cli = RaCliProc(name='test.cli') self.colony = RaColony(name='test.colony') self.cluster = RaCluster(name='test.cluster') self.manifest = RaManifest(northbound_listing=None, persist_dir_name='test') self.assertEqual(self.manifest.netconf_trace, NetconfTrace.AUTO) # Put the CLI tasklet into a proc self.cli_proc = RaProc(name='test.proc.cli') self.cli_proc.add_component(self.cli) # Add the CLI process to the VM self.vm = RaVm(name='test.vm') self.vm.add_component(self.cli_proc) self.cluster.add_component(self.vm) self.colony.add_component(self.cluster) self.manifest.add_component(self.colony) def test_iter(self): # The components of the manifest are returned by a depth-first # traversal. reference = [ 'test.cli', 'test.proc.cli', 'test.vm', 'test.cluster', 'test.colony', ] for actual, expected in zip(self.manifest, reference): self.assertEqual(actual.name, expected) def test_remove_component(self): # Remove the VM self.manifest.remove_component(self.vm) # The VM component and all of its children should have been removed # from the manifest self.assertIsNone(self.manifest.find_by_class(RaCliProc)) self.assertIsNone(self.manifest.find_by_class(RaProc)) # The only remaining components are the cluster and the colony self.assertIsNotNone(self.manifest.find_by_class(RaCluster)) self.assertIsNotNone(self.manifest.find_by_class(RaColony)) def test_remove_empty_procs(self): self.manifest.remove_component(self.cli) self.manifest.remove_empty_procs() self.assertIsNone(self.manifest.find_by_class(RaProc)) def test_assign_leading_vm(self): self.manifest.assign_leading_vm() reference = [ 'test.cli', 'test.proc.cli', 'test.vm', 'test.colony', ] for actual, expected in zip(self.manifest, reference): self.assertEqual(actual.name, expected) def test_list_by_class(self): # All components derive from RaManifestObject, so each component should # be in the list. components = self.manifest.list_by_class(RaManifestObject) self.assertEqual(5, len(components)) # There is only one RaProc component in the manifest procs = self.manifest.list_by_class(RaProc) self.assertEqual(1, len(procs)) def test_find_by_class(self): self.assertTrue(self.manifest.find_by_class(RaCliProc) == self.cli) self.assertTrue(self.manifest.find_by_class(RaProc) == self.cli_proc) self.assertTrue(self.manifest.find_by_class(RaColony) == self.colony) self.assertTrue(self.manifest.find_by_class(RaNativeProcess) == self.cli) def test_find_ancestor_by_class(self): self.assertEqual(self.cli_proc, self.manifest.find_ancestor_by_class(RaProc, self.cli)) def test_find_enclosing_cluster(self): self.assertEqual(self.cluster, self.manifest.find_enclosing_cluster(self.cli)) def test_find_enclosing_colony(self): self.assertEqual(self.colony, self.manifest.find_enclosing_colony(self.cli))
class TestManifest(unittest.TestCase): def setUp(self): # Create a system that consists of a cli tasklet # running inside a VM, that is running within a colony. self.cli = RaCliProc(name='test.cli') self.colony = RaColony(name='test.colony') self.cluster = RaCluster(name='test.cluster') self.manifest = RaManifest(northbound_listing=None, persist_dir_name='test') self.assertEqual(self.manifest.netconf_trace, NetconfTrace.AUTO) # Put the CLI tasklet into a proc self.cli_proc = RaProc(name='test.proc.cli') self.cli_proc.add_component(self.cli) # Add the CLI process to the VM self.vm = RaVm(name='test.vm') self.vm.add_component(self.cli_proc) self.cluster.add_component(self.vm) self.colony.add_component(self.cluster) self.manifest.add_component(self.colony) def test_iter(self): # The components of the manifest are returned by a depth-first # traversal. reference = [ 'test.cli', 'test.proc.cli', 'test.vm', 'test.cluster', 'test.colony', ] for actual, expected in zip(self.manifest, reference): self.assertEqual(actual.name, expected) def test_remove_component(self): # Remove the VM self.manifest.remove_component(self.vm) # The VM component and all of its children should have been removed # from the manifest self.assertIsNone(self.manifest.find_by_class(RaCliProc)) self.assertIsNone(self.manifest.find_by_class(RaProc)) # The only remaining components are the cluster and the colony self.assertIsNotNone(self.manifest.find_by_class(RaCluster)) self.assertIsNotNone(self.manifest.find_by_class(RaColony)) def test_remove_empty_procs(self): self.manifest.remove_component(self.cli) self.manifest.remove_empty_procs() self.assertIsNone(self.manifest.find_by_class(RaProc)) def test_assign_leading_vm(self): self.manifest.assign_leading_vm() reference = [ 'test.cli', 'test.proc.cli', 'test.vm', 'test.colony', ] for actual, expected in zip(self.manifest, reference): self.assertEqual(actual.name, expected) def test_list_by_class(self): # All components derive from RaManifestObject, so each component should # be in the list. components = self.manifest.list_by_class(RaManifestObject) self.assertEqual(5, len(components)) # There is only one RaProc component in the manifest procs = self.manifest.list_by_class(RaProc) self.assertEqual(1, len(procs)) def test_find_by_class(self): self.assertTrue(self.manifest.find_by_class(RaCliProc) == self.cli) self.assertTrue(self.manifest.find_by_class(RaProc) == self.cli_proc) self.assertTrue(self.manifest.find_by_class(RaColony) == self.colony) self.assertTrue( self.manifest.find_by_class(RaNativeProcess) == self.cli) def test_find_ancestor_by_class(self): self.assertEqual( self.cli_proc, self.manifest.find_ancestor_by_class(RaProc, self.cli)) def test_find_enclosing_cluster(self): self.assertEqual(self.cluster, self.manifest.find_enclosing_cluster(self.cli)) def test_find_enclosing_colony(self): self.assertEqual(self.colony, self.manifest.find_enclosing_colony(self.cli))