本文整理匯總了Python中cloudinstall.placement.controller.PlacementController.is_assigned方法的典型用法代碼示例。如果您正苦於以下問題:Python PlacementController.is_assigned方法的具體用法?Python PlacementController.is_assigned怎麽用?Python PlacementController.is_assigned使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cloudinstall.placement.controller.PlacementController
的用法示例。
在下文中一共展示了PlacementController.is_assigned方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: PlacementControllerTestCase
# 需要導入模塊: from cloudinstall.placement.controller import PlacementController [as 別名]
# 或者: from cloudinstall.placement.controller.PlacementController import is_assigned [as 別名]
#.........這裏部分代碼省略.........
self.pc.reset_assigned_deployed()
self.assertEqual(0, len(self.pc.unassigned_undeployed_services()))
def test_reset_unassigned_undeployed_two(self):
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.LXC)
self.pc.assign(self.mock_machine_2, CharmKeystone, AssignmentType.KVM)
self.pc.reset_assigned_deployed()
self.assertEqual(len(self.pc.charm_classes()) - 2,
len(self.pc.unassigned_undeployed_services()))
def test_reset_excepting_compute(self):
for cc in self.pc.charm_classes():
if cc.charm_name == 'nova-compute':
continue
self.pc.assign(self.mock_machine, cc, AssignmentType.LXC)
self.pc.reset_assigned_deployed()
self.assertEqual(len(self.pc.unassigned_undeployed_services()), 1)
def test_unassigned_undeployed(self):
all_charms = set(self.pc.charm_classes())
self.pc.assign(self.mock_machine, CharmKeystone, AssignmentType.KVM)
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.KVM)
self.pc.mark_deployed(self.mock_machine, CharmKeystone,
AssignmentType.KVM)
self.assertTrue(CharmKeystone not in
self.pc.unassigned_undeployed_services())
self.assertTrue(CharmNovaCompute not in
self.pc.unassigned_undeployed_services())
self.assertTrue(self.pc.is_deployed(CharmKeystone))
self.assertTrue(self.pc.is_assigned(CharmNovaCompute))
self.assertTrue(len(all_charms) - 2,
len(self.pc.unassigned_undeployed_services()))
n_k_as = self.pc.assignment_machine_count_for_charm(CharmKeystone)
self.assertEqual(n_k_as, 0)
n_k_dl = self.pc.deployment_machine_count_for_charm(CharmKeystone)
self.assertEqual(n_k_dl, 1)
n_nc_as = self.pc.assignment_machine_count_for_charm(CharmNovaCompute)
self.assertEqual(n_nc_as, 1)
n_nc_dl = self.pc.deployment_machine_count_for_charm(CharmNovaCompute)
self.assertEqual(n_nc_dl, 0)
def test_deployed_charms_starts_empty(self):
"Initially there are no deployed charms"
self.assertEqual(0, len(self.pc.deployed_charm_classes()))
def test_mark_deployed_unsets_assignment(self):
"Setting a placement to deployed removes it from assignment dict"
self.pc.assign(self.mock_machine, CharmKeystone, AssignmentType.KVM)
self.assertEqual([CharmKeystone], self.pc.assigned_charm_classes())
self.pc.mark_deployed(self.mock_machine, CharmKeystone,
AssignmentType.KVM)
self.assertEqual([CharmKeystone], self.pc.deployed_charm_classes())
self.assertEqual([], self.pc.assigned_charm_classes())
def test_set_deployed_unsets_assignment_only_once(self):
"Setting a placement to deployed removes it from assignment dict"
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.KVM)
self.pc.assign(self.mock_machine_2, CharmNovaCompute,
AssignmentType.KVM)
self.assertEqual([CharmNovaCompute], self.pc.assigned_charm_classes())
示例2: PlacementControllerTestCase
# 需要導入模塊: from cloudinstall.placement.controller import PlacementController [as 別名]
# 或者: from cloudinstall.placement.controller.PlacementController import is_assigned [as 別名]
#.........這裏部分代碼省略.........
def test_swift_unrequired_then_required(self):
"Swift and swift-proxy are both optional until you add swift"
self.assertFalse(self.pc.service_is_required(CharmSwift))
self.assertFalse(self.pc.service_is_required(CharmSwiftProxy))
self.pc.assign(self.mock_machine, CharmSwift, AssignmentType.LXC)
self.assertTrue(self.pc.service_is_required(CharmSwift))
self.assertTrue(self.pc.service_is_required(CharmSwiftProxy))
def test_swift_proxy_unrequired_then_required(self):
"Swift and swift-proxy are both optional until you add swift-proxy"
self.assertFalse(self.pc.service_is_required(CharmSwift))
self.assertFalse(self.pc.service_is_required(CharmSwiftProxy))
self.pc.assign(self.mock_machine, CharmSwiftProxy, AssignmentType.LXC)
self.assertTrue(self.pc.service_is_required(CharmSwift))
# Only one swift-proxy is required, so now that we've added
# it, it is still not required:
self.assertFalse(self.pc.service_is_required(CharmSwiftProxy))
def test_persistence(self):
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.LXC)
self.pc.assign(self.mock_machine_2, CharmKeystone, AssignmentType.KVM)
cons1 = PropertyMock(return_value={})
type(self.mock_machine).constraints = cons1
cons2 = PropertyMock(return_value={'cpu': 8})
type(self.mock_machine_2).constraints = cons2
with TemporaryFile(mode='w+', encoding='utf-8') as tempf:
self.pc.save(tempf)
tempf.seek(0)
newpc = PlacementController(self.mock_maas_state, self.mock_opts)
newpc.load(tempf)
self.assertEqual(self.pc.assignments, newpc.assignments)
self.assertEqual(self.pc.machines_used(), newpc.machines_used())
self.assertEqual(self.pc.placed_charm_classes(),
newpc.placed_charm_classes())
m2 = next((m for m in newpc.machines_used()
if m.instance_id == 'fake-instance-id-2'))
self.assertEqual(m2.constraints, {'cpu': 8})
def test_load_machines_single(self):
singlepc = PlacementController(None, self.mock_opts)
fake_assignments = {'fake_iid': {'constraints': {},
'assignments': {'KVM':
['nova-compute']}},
'fake_iid_2': {'constraints': {'cpu': 8},
'assignments':
{'BareMetal': ['nova-compute']}}}
with TemporaryFile(mode='w+', encoding='utf-8') as tempf:
yaml.dump(fake_assignments, tempf)
tempf.seek(0)
singlepc.load(tempf)
self.assertEqual(set([m.instance_id for m in
singlepc.machines_used()]),
set(['fake_iid', 'fake_iid_2']))
m2 = next((m for m in singlepc.machines_used()
if m.instance_id == 'fake_iid_2'))
self.assertEqual(m2.constraints, {'cpu': 8})
def test_load_error_mismatch_charm_name(self):
"""Should safely ignore (and log) a charm name in a placement file
that can't be matched to a loaded charm class."""
singlepc = PlacementController(None, self.mock_opts)
fake_assignments = {'fake_iid': {'constraints': {},
'assignments': {'KVM':
['non-existent']}},
'fake_iid_2': {'constraints': {'cpu': 8},
'assignments':
{'BareMetal': ['nova-compute']}}}
with TemporaryFile(mode='w+', encoding='utf-8') as tempf:
yaml.dump(fake_assignments, tempf)
tempf.seek(0)
singlepc.load(tempf)
self.assertEqual(set([m.instance_id for m in
singlepc.machines_used()]),
set(['fake_iid_2']))
m2 = next((m for m in singlepc.machines_used()
if m.instance_id == 'fake_iid_2'))
self.assertEqual(m2.constraints, {'cpu': 8})
def test_is_assigned(self):
self.assertFalse(self.pc.is_assigned(CharmSwiftProxy,
self.mock_machine))
self.pc.assign(self.mock_machine, CharmSwiftProxy, AssignmentType.LXC)
self.assertTrue(self.pc.is_assigned(CharmSwiftProxy,
self.mock_machine))
def test_double_clear_ok(self):
"""clearing assignments for a machine that isn't assigned (anymore) is
OK and should do nothing
"""
self.pc.assign(self.mock_machine, CharmSwiftProxy, AssignmentType.LXC)
self.pc.clear_assignments(self.mock_machine)
self.pc.clear_assignments(self.mock_machine)
self.pc.clear_assignments(self.mock_machine_2)