JujuApplicationExists,
JujuInvalidK8sConfiguration,
JujuLeaderUnitNotFound,
+ JujuError,
)
from n2vc.k8s_juju_conn import generate_rbac_id
mock_disconnect_model.assert_called()
+@asynctest.mock.patch("n2vc.libjuju.Libjuju.get_controller")
+@asynctest.mock.patch("n2vc.libjuju.Libjuju.get_model")
+@asynctest.mock.patch("n2vc.libjuju.Libjuju.disconnect_model")
+@asynctest.mock.patch("n2vc.libjuju.Libjuju.disconnect_controller")
+@asynctest.mock.patch(
+ "juju.model.Model.applications", new_callable=asynctest.PropertyMock
+)
+@asynctest.mock.patch("juju.model.Model.get_action_status")
+@asynctest.mock.patch("juju.model.Model.get_action_output")
+@asynctest.mock.patch("n2vc.libjuju.Libjuju.get_actions")
+class GetExecutedActionsTest(LibjujuTestCase):
+ def setUp(self):
+ super(GetExecutedActionsTest, self).setUp()
+
+ def test_exception(
+ self,
+ mock_get_actions,
+ mock_get_action_output,
+ mock_get_action_status,
+ mock_applications,
+ mock_disconnect_controller,
+ mock_disconnect_model,
+ mock_get_model,
+ mock_get_controller,
+ ):
+ mock_get_model.return_value = None
+ with self.assertRaises(JujuError):
+ self.loop.run_until_complete(self.libjuju.get_executed_actions("model"))
+
+ mock_get_controller.assert_called_once()
+ mock_disconnect_controller.assert_called_once()
+ mock_get_model.assert_called_once()
+ mock_disconnect_model.assert_not_called()
+
+ def test_success(
+ self,
+ mock_get_actions,
+ mock_get_action_output,
+ mock_get_action_status,
+ mock_applications,
+ mock_disconnect_controller,
+ mock_disconnect_model,
+ mock_get_model,
+ mock_get_controller,
+ ):
+ mock_get_model.return_value = juju.model.Model()
+ mock_applications.return_value = {"existing_app"}
+ mock_get_actions.return_value = {"action_name": "description"}
+ mock_get_action_status.return_value = {"id": "status"}
+ mock_get_action_output.return_value = {"output": "completed"}
+
+ executed_actions = self.loop.run_until_complete(
+ self.libjuju.get_executed_actions("model")
+ )
+ expected_result = [{'id': 'id', 'action': 'action_name',
+ 'status': 'status', 'output': 'completed'}]
+ self.assertListEqual(expected_result, executed_actions)
+ self.assertIsInstance(executed_actions, list)
+
+ mock_get_controller.assert_called_once()
+ mock_get_model.assert_called_once()
+ mock_disconnect_controller.assert_called_once()
+ mock_disconnect_model.assert_called_once()
+
+
+@asynctest.mock.patch("n2vc.libjuju.Libjuju.get_controller")
+@asynctest.mock.patch("n2vc.libjuju.Libjuju.get_model")
+@asynctest.mock.patch("n2vc.libjuju.Libjuju.disconnect_model")
+@asynctest.mock.patch("n2vc.libjuju.Libjuju.disconnect_controller")
+@asynctest.mock.patch("n2vc.libjuju.Libjuju._get_application")
+class GetApplicationConfigsTest(LibjujuTestCase):
+ def setUp(self):
+ super(GetApplicationConfigsTest, self).setUp()
+
+ def test_exception(
+ self,
+ mock_get_application,
+ mock_disconnect_controller,
+ mock_disconnect_model,
+ mock_get_model,
+ mock_get_controller,
+ ):
+ mock_get_model.return_value = None
+ with self.assertRaises(JujuError):
+ self.loop.run_until_complete(
+ self.libjuju.get_application_configs("model", "app"))
+
+ mock_get_controller.assert_called_once()
+ mock_disconnect_controller.assert_called_once()
+ mock_get_model.assert_called_once()
+ mock_disconnect_model.assert_not_called()
+
+ def test_success(
+ self,
+ mock_get_application,
+ mock_disconnect_controller,
+ mock_disconnect_model,
+ mock_get_model,
+ mock_get_controller,
+ ):
+ mock_get_application.return_value = FakeApplication()
+ application_configs = self.loop.run_until_complete(self.libjuju
+ .get_application_configs("model", "app"))
+
+ self.assertEqual(application_configs, ["app_config"])
+
+ mock_get_controller.assert_called_once()
+ mock_get_model.assert_called_once()
+ mock_disconnect_controller.assert_called_once()
+ mock_disconnect_model.assert_called_once()
+
+
@asynctest.mock.patch("juju.controller.Controller.get_model")
class GetModelTest(LibjujuTestCase):
def setUp(self):
mock_get_metrics.assert_called_once()
+@asynctest.mock.patch("n2vc.libjuju.Libjuju.get_controller")
+@asynctest.mock.patch("n2vc.libjuju.Libjuju.get_model")
+@asynctest.mock.patch("n2vc.libjuju.Libjuju.get_executed_actions")
+@asynctest.mock.patch("n2vc.libjuju.Libjuju.get_actions")
+@asynctest.mock.patch("n2vc.libjuju.Libjuju.get_application_configs")
+@asynctest.mock.patch("n2vc.libjuju.Libjuju._get_application")
+class UpdateVcaStatusTest(N2VCJujuConnTestCase):
+ def setUp(self):
+ super(UpdateVcaStatusTest, self).setUp()
+
+ def test_success(
+ self,
+ mock_get_application,
+ mock_get_application_configs,
+ mock_get_actions,
+ mock_get_executed_actions,
+ mock_get_model,
+ mock_get_controller,
+ ):
+ self.loop.run_until_complete(self.n2vc.update_vca_status(
+ {"model": {"applications": {"app": {"actions": {}}}}}))
+ mock_get_executed_actions.assert_called_once()
+ mock_get_actions.assert_called_once()
+ mock_get_application_configs.assert_called_once()
+
+ def test_exception(
+ self,
+ mock_get_application,
+ mock_get_application_configs,
+ mock_get_actions,
+ mock_get_executed_actions,
+ mock_get_model,
+ mock_get_controller,
+ ):
+ mock_get_model.return_value = None
+ mock_get_executed_actions.side_effect = Exception()
+ with self.assertRaises(Exception):
+ self.loop.run_until_complete(self.n2vc.update_vca_status(
+ {"model": {"applications": {"app": {"actions": {}}}}}))
+ mock_get_executed_actions.assert_not_called()
+ mock_get_actions.assert_not_called_once()
+ mock_get_application_configs.assert_not_called_once()
+
+
@asynctest.mock.patch("n2vc.libjuju.Libjuju.model_exists")
@asynctest.mock.patch("osm_common.fslocal.FsLocal.file_exists")
@asynctest.mock.patch(