本文整理匯總了Python中cloudinstall.placement.controller.PlacementController.assignments_for_machine方法的典型用法代碼示例。如果您正苦於以下問題:Python PlacementController.assignments_for_machine方法的具體用法?Python PlacementController.assignments_for_machine怎麽用?Python PlacementController.assignments_for_machine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cloudinstall.placement.controller.PlacementController
的用法示例。
在下文中一共展示了PlacementController.assignments_for_machine方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: PlacementControllerTestCase
# 需要導入模塊: from cloudinstall.placement.controller import PlacementController [as 別名]
# 或者: from cloudinstall.placement.controller.PlacementController import assignments_for_machine [as 別名]
class PlacementControllerTestCase(unittest.TestCase):
def setUp(self):
self.mock_maas_state = MagicMock()
with NamedTemporaryFile(mode='w+', encoding='utf-8') as tempf:
utils.spew(tempf.name, yaml.dump(dict()))
self.conf = Config({}, tempf.name)
self.pc = PlacementController(self.mock_maas_state,
self.conf)
self.mock_machine = MagicMock(name='machine1')
pmid = PropertyMock(return_value='fake-instance-id-1')
type(self.mock_machine).instance_id = pmid
self.mock_machine_2 = MagicMock(name='machine2')
pmid2 = PropertyMock(return_value='fake-instance-id-2')
type(self.mock_machine_2).instance_id = pmid2
self.mock_machines = [self.mock_machine, self.mock_machine_2]
self.mock_maas_state.machines.return_value = self.mock_machines
def test_get_assignments_atype(self):
self.assertEqual(0,
len(self.pc.get_assignments(CharmNovaCompute)))
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.LXC)
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.LXC)
md = self.pc.get_assignments(CharmNovaCompute)
self.assertEqual(1, len(md))
self.assertEqual(2, len(md[AssignmentType.LXC]))
def _do_test_simple_assign_type(self, assignment_type):
self.pc.assign(self.mock_machine, CharmNovaCompute, assignment_type)
print("assignments is {}".format(self.pc.assignments))
machines = self.pc.get_assignments(CharmNovaCompute)
print('machines for charm is {}'.format(machines))
self.assertEqual(machines,
{assignment_type: [self.mock_machine]})
ma = self.pc.assignments_for_machine(self.mock_machine)
self.assertEqual(ma[assignment_type], [CharmNovaCompute])
def test_simple_assign_bare(self):
self._do_test_simple_assign_type(AssignmentType.BareMetal)
def test_simple_assign_lxc(self):
self._do_test_simple_assign_type(AssignmentType.LXC)
def test_simple_assign_kvm(self):
self._do_test_simple_assign_type(AssignmentType.KVM)
def test_assign_nonmulti(self):
self.pc.assign(self.mock_machine, CharmKeystone, AssignmentType.LXC)
self.assertEqual(self.pc.get_assignments(CharmKeystone),
{AssignmentType.LXC: [self.mock_machine]})
self.pc.assign(self.mock_machine, CharmKeystone, AssignmentType.KVM)
self.assertEqual(self.pc.get_assignments(CharmKeystone),
{AssignmentType.KVM: [self.mock_machine]})
am = self.pc.assignments_for_machine(self.mock_machine)
self.assertEqual(am[AssignmentType.KVM], [CharmKeystone])
self.assertEqual(am[AssignmentType.LXC], [])
def test_assign_multi(self):
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.LXC)
self.assertEqual(self.pc.get_assignments(CharmNovaCompute),
{AssignmentType.LXC: [self.mock_machine]})
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.KVM)
self.assertEqual(self.pc.get_assignments(CharmNovaCompute),
{AssignmentType.LXC: [self.mock_machine],
AssignmentType.KVM: [self.mock_machine]})
ma = self.pc.assignments_for_machine(self.mock_machine)
self.assertEqual(ma[AssignmentType.LXC], [CharmNovaCompute])
self.assertEqual(ma[AssignmentType.KVM], [CharmNovaCompute])
def test_remove_assignment_multi(self):
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.LXC)
self.pc.assign(self.mock_machine_2, CharmNovaCompute,
AssignmentType.LXC)
mfc = self.pc.get_assignments(CharmNovaCompute)
mfc_lxc = set(mfc[AssignmentType.LXC])
self.assertEqual(mfc_lxc, set(self.mock_machines))
self.pc.clear_assignments(self.mock_machine)
self.assertEqual(self.pc.get_assignments(CharmNovaCompute),
{AssignmentType.LXC: [self.mock_machine_2]})
def test_gen_defaults(self):
satisfies_importstring = 'cloudinstall.placement.controller.satisfies'
with patch(satisfies_importstring) as mock_satisfies:
mock_satisfies.return_value = (True, )
defs = self.pc.gen_defaults(charm_classes=[CharmNovaCompute,
CharmKeystone],
maas_machines=[self.mock_machine,
#.........這裏部分代碼省略.........
示例2: PlacementControllerTestCase
# 需要導入模塊: from cloudinstall.placement.controller import PlacementController [as 別名]
# 或者: from cloudinstall.placement.controller.PlacementController import assignments_for_machine [as 別名]
class PlacementControllerTestCase(unittest.TestCase):
def setUp(self):
self.mock_maas_state = MagicMock()
self.mock_opts = MagicMock()
swopt = PropertyMock(return_value=False)
type(self.mock_opts).enable_swift = swopt
self.pc = PlacementController(self.mock_maas_state,
self.mock_opts)
self.mock_machine = MagicMock(name='machine1')
pmid = PropertyMock(return_value='fake-instance-id-1')
type(self.mock_machine).instance_id = pmid
self.mock_machine_2 = MagicMock(name='machine2')
pmid2 = PropertyMock(return_value='fake-instance-id-2')
type(self.mock_machine_2).instance_id = pmid2
self.mock_machines = [self.mock_machine, self.mock_machine_2]
self.mock_maas_state.machines.return_value = self.mock_machines
def test_machines_for_charm_atype(self):
self.assertEqual(0, len(self.pc.machines_for_charm(CharmNovaCompute)))
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.LXC)
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.LXC)
md = self.pc.machines_for_charm(CharmNovaCompute)
self.assertEqual(1, len(md))
self.assertEqual(2, len(md[AssignmentType.LXC]))
def _do_test_simple_assign_type(self, assignment_type):
self.pc.assign(self.mock_machine, CharmNovaCompute, assignment_type)
print("assignments is {}".format(self.pc.assignments))
machines = self.pc.machines_for_charm(CharmNovaCompute)
print('machines for charm is {}'.format(machines))
self.assertEqual(machines,
{assignment_type: [self.mock_machine]})
ma = self.pc.assignments_for_machine(self.mock_machine)
self.assertEqual(ma[assignment_type], [CharmNovaCompute])
def test_simple_assign_bare(self):
self._do_test_simple_assign_type(AssignmentType.BareMetal)
def test_simple_assign_lxc(self):
self._do_test_simple_assign_type(AssignmentType.LXC)
def test_simple_assign_kvm(self):
self._do_test_simple_assign_type(AssignmentType.KVM)
def test_assign_nonmulti(self):
self.pc.assign(self.mock_machine, CharmKeystone, AssignmentType.LXC)
self.assertEqual(self.pc.machines_for_charm(CharmKeystone),
{AssignmentType.LXC: [self.mock_machine]})
self.pc.assign(self.mock_machine, CharmKeystone, AssignmentType.KVM)
self.assertEqual(self.pc.machines_for_charm(CharmKeystone),
{AssignmentType.KVM: [self.mock_machine]})
am = self.pc.assignments_for_machine(self.mock_machine)
self.assertEqual(am[AssignmentType.KVM], [CharmKeystone])
self.assertEqual(am[AssignmentType.LXC], [])
def test_assign_multi(self):
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.LXC)
self.assertEqual(self.pc.machines_for_charm(CharmNovaCompute),
{AssignmentType.LXC: [self.mock_machine]})
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.KVM)
self.assertEqual(self.pc.machines_for_charm(CharmNovaCompute),
{AssignmentType.LXC: [self.mock_machine],
AssignmentType.KVM: [self.mock_machine]})
ma = self.pc.assignments_for_machine(self.mock_machine)
self.assertEqual(ma[AssignmentType.LXC], [CharmNovaCompute])
self.assertEqual(ma[AssignmentType.KVM], [CharmNovaCompute])
def test_remove_assignment_multi(self):
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.LXC)
self.pc.assign(self.mock_machine_2, CharmNovaCompute,
AssignmentType.LXC)
mfc = self.pc.machines_for_charm(CharmNovaCompute)
mfc_lxc = set(mfc[AssignmentType.LXC])
self.assertEqual(mfc_lxc, set(self.mock_machines))
self.pc.clear_assignments(self.mock_machine)
self.assertEqual(self.pc.machines_for_charm(CharmNovaCompute),
{AssignmentType.LXC: [self.mock_machine_2]})
def test_gen_defaults(self):
satisfies_importstring = 'cloudinstall.placement.controller.satisfies'
with patch(satisfies_importstring) as mock_satisfies:
mock_satisfies.return_value = (True, )
defs = self.pc.gen_defaults(charm_classes=[CharmNovaCompute,
CharmKeystone],
maas_machines=[self.mock_machine,
self.mock_machine_2])
#.........這裏部分代碼省略.........