def test_unknown_pod_raises_UnknownPodType(self): unknown_type = factory.make_name("unknown") pod_id = random.randint(1, 10) pod_name = factory.make_name("pod") with ExpectedException(exceptions.UnknownPodType): yield pods.decompose_machine( unknown_type, {}, pod_id=pod_id, name=pod_name )
def test_handles_driver_raising_NotImplementedError(self): fake_driver = MagicMock() fake_driver.name = factory.make_name("pod") fake_driver.decompose.return_value = fail(NotImplementedError()) 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.decompose_machine( fake_driver.name, {}, pod_id=pod_id, name=pod_name )
def test_handles_driver_not_returning_hints(self): fake_driver = MagicMock() fake_driver.name = factory.make_name("pod") fake_driver.decompose.return_value = succeed(object()) 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'; 'decompose' " "returned invalid result." % fake_driver.name)): yield pods.decompose_machine(fake_driver.name, {}, pod_id=pod_id, name=pod_name)
def test_handles_driver_not_returning_Deferred(self): fake_driver = MagicMock() fake_driver.name = factory.make_name("pod") fake_driver.decompose.return_value = None 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'; 'decompose' did not " "return Deferred." % fake_driver.name), ): yield pods.decompose_machine(fake_driver.name, {}, pod_id=pod_id, name=pod_name)
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.decompose.return_value = fail(fake_exception) 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.decompose_machine(fake_driver.name, {}, pod_id=pod_id, name=pod_name)
def test_works_when_driver_returns_hints(self): hints = DiscoveredPodHints( cores=random.randint(1, 8), cpu_speed=random.randint(1000, 2000), memory=random.randint(1024, 8192), local_storage=0, ) fake_driver = MagicMock() fake_driver.name = factory.make_name("pod") fake_driver.decompose.return_value = succeed(hints) pod_id = random.randint(1, 10) pod_name = factory.make_name("pod") self.patch(PodDriverRegistry, "get_item").return_value = fake_driver result = yield pods.decompose_machine( fake_driver.name, {}, pod_id=pod_id, name=pod_name ) self.assertEqual({"hints": hints}, result)