def _create_health_check_task(self):
return self.loop.create_task(self.health_check())
- async def get_controller(self, timeout: float = 5.0) -> Controller:
+ async def get_controller(self, timeout: float = 15.0) -> Controller:
"""
Get controller
"""
controller = await self.get_controller()
- model = await self.get_model(controller, model_name)
+ model = None
try:
+ model = await self.get_model(controller, model_name)
self.log.debug("Destroying model {}".format(model_name))
uuid = model.info.uuid
raise Exception(
"Timeout waiting for model {} to be destroyed".format(model_name)
)
+ except Exception as e:
+ if model:
+ await self.disconnect_model(model)
+ raise e
finally:
await self.disconnect_controller(controller)
self.assertTrue(isinstance(value, str))
+@asynctest.mock.patch("asyncio.sleep")
class WaitForModelTest(asynctest.TestCase):
@asynctest.mock.patch("juju.client.connector.Connector.connect")
def setUp(self, mock_connect=None):
self.model = Model()
@asynctest.mock.patch("juju.model.Model.block_until")
- def test_wait_for_model(self, mock_block_until):
+ def test_wait_for_model(self, mock_block_until, mock_sleep):
self.loop.run_until_complete(
JujuModelWatcher.wait_for_model(self.model, timeout=None)
)
@asynctest.mock.patch("asyncio.ensure_future")
@asynctest.mock.patch("asyncio.wait")
- def test_wait_for_model_exception(self, mock_wait, mock_ensure_future):
+ def test_wait_for_model_exception(self, mock_wait, mock_ensure_future, mock_sleep):
task = Mock()
mock_ensure_future.return_value = task
mock_wait.side_effect = Exception
self.k8s_juju_conn._create_cluster_role = Mock()
self.k8s_juju_conn._create_service_account = Mock()
self.k8s_juju_conn._create_cluster_role_binding = Mock()
+ self.k8s_juju_conn._delete_cluster_role = Mock()
+ self.k8s_juju_conn._delete_service_account = Mock()
+ self.k8s_juju_conn._delete_cluster_role_binding = Mock()
self.k8s_juju_conn._get_secret_data = AsyncMock()
self.k8s_juju_conn._get_secret_data.return_value = ("token", "cacert")