Example #1
0
 def test_handles_driver_resolving_to_tuple_of_discovered(self):
     fake_driver = MagicMock()
     fake_driver.name = factory.make_name("pod")
     fake_request = self.make_requested_machine()
     pod_id = random.randint(1, 10)
     pod_name = factory.make_name("pod")
     machine = DiscoveredMachine(
         hostname=factory.make_name("hostname"),
         architecture="amd64/generic",
         cores=random.randint(1, 8),
         cpu_speed=random.randint(1000, 3000),
         memory=random.randint(1024, 8192),
         block_devices=[],
         interfaces=[],
     )
     hints = DiscoveredPodHints(
         cores=random.randint(1, 8),
         cpu_speed=random.randint(1000, 2000),
         memory=random.randint(1024, 8192),
         local_storage=0,
     )
     fake_driver.compose.return_value = succeed((machine, hints))
     self.patch(PodDriverRegistry, "get_item").return_value = fake_driver
     result = yield pods.compose_machine(
         fake_driver.name, {}, fake_request, pod_id=pod_id, name=pod_name
     )
     self.assertEqual({"machine": machine, "hints": hints}, result)
Example #2
0
 def test_unknown_pod_raises_UnknownPodType(self):
     unknown_type = factory.make_name("unknown")
     fake_request = self.make_requested_machine()
     pod_id = random.randint(1, 10)
     pod_name = factory.make_name("pod")
     with ExpectedException(exceptions.UnknownPodType):
         yield pods.compose_machine(
             unknown_type, {}, fake_request, pod_id=pod_id, name=pod_name
         )
Example #3
0
 def test_handles_driver_raising_NotImplementedError(self):
     fake_driver = MagicMock()
     fake_driver.name = factory.make_name("pod")
     fake_driver.compose.return_value = fail(NotImplementedError())
     fake_request = self.make_requested_machine()
     pod_id = random.randint(1, 10)
     pod_name = factory.make_name("pod")
     self.patch(PodDriverRegistry, "get_item").return_value = fake_driver
     with ExpectedException(NotImplementedError):
         yield pods.compose_machine(fake_driver.name, {},
                                    fake_request,
                                    pod_id=pod_id,
                                    name=pod_name)
Example #4
0
 def test_handles_driver_resolving_to_None(self):
     fake_driver = MagicMock()
     fake_driver.name = factory.make_name("pod")
     fake_driver.compose.return_value = succeed(None)
     fake_request = self.make_requested_machine()
     pod_id = random.randint(1, 10)
     pod_name = factory.make_name("pod")
     self.patch(PodDriverRegistry, "get_item").return_value = fake_driver
     with ExpectedException(exceptions.PodInvalidResources):
         yield pods.compose_machine(fake_driver.name, {},
                                    fake_request,
                                    pod_id=pod_id,
                                    name=pod_name)
Example #5
0
 def test_handles_driver_not_resolving_to_tuple_of_discovered(self):
     fake_driver = MagicMock()
     fake_driver.name = factory.make_name("pod")
     fake_driver.compose.return_value = succeed((object(), object()))
     fake_request = self.make_requested_machine()
     pod_id = random.randint(1, 10)
     pod_name = factory.make_name("pod")
     self.patch(PodDriverRegistry, "get_item").return_value = fake_driver
     with ExpectedException(
             exceptions.PodActionFail,
             re.escape("bad pod driver '%s'; 'compose' returned "
                       "invalid result." % fake_driver.name)):
         yield pods.compose_machine(fake_driver.name, {},
                                    fake_request,
                                    pod_id=pod_id,
                                    name=pod_name)
Example #6
0
 def test_handles_driver_not_returning_Deferred(self):
     fake_driver = MagicMock()
     fake_driver.name = factory.make_name("pod")
     fake_driver.compose.return_value = None
     fake_request = self.make_requested_machine()
     pod_id = random.randint(1, 10)
     pod_name = factory.make_name("pod")
     self.patch(PodDriverRegistry, "get_item").return_value = fake_driver
     with ExpectedException(
             exceptions.PodActionFail,
             re.escape("bad pod driver '%s'; 'compose' did not "
                       "return Deferred." % fake_driver.name)):
         yield pods.compose_machine(fake_driver.name, {},
                                    fake_request,
                                    pod_id=pod_id,
                                    name=pod_name)
Example #7
0
 def test_handles_driver_raising_any_Exception(self):
     fake_driver = MagicMock()
     fake_driver.name = factory.make_name("pod")
     fake_exception_type = factory.make_exception_type()
     fake_exception_msg = factory.make_name("error")
     fake_exception = fake_exception_type(fake_exception_msg)
     fake_driver.compose.return_value = fail(fake_exception)
     fake_request = self.make_requested_machine()
     pod_id = random.randint(1, 10)
     pod_name = factory.make_name("pod")
     self.patch(PodDriverRegistry, "get_item").return_value = fake_driver
     with ExpectedException(
             exceptions.PodActionFail,
             re.escape("Failed talking to pod: " + fake_exception_msg)):
         yield pods.compose_machine(fake_driver.name, {},
                                    fake_request,
                                    pod_id=pod_id,
                                    name=pod_name)