diff --git a/sahara/cli/sahara_engine.py b/sahara/cli/sahara_engine.py index 143d2592bf..88c6328fbb 100644 --- a/sahara/cli/sahara_engine.py +++ b/sahara/cli/sahara_engine.py @@ -41,6 +41,7 @@ if os.path.exists(os.path.join(possible_topdir, i18n.enable_lazy() +from sahara.api import acl import sahara.main as server from sahara.service import ops @@ -48,6 +49,12 @@ from sahara.service import ops def main(): server.setup_common(possible_topdir, 'engine') + from oslo.config import cfg + # NOTE(apavlov): acl.wrap is called here to set up auth_uri value + # in context by using keystone functionality (mostly to avoid + # code duplication). + acl.wrap(None, cfg.CONF) + server.setup_sahara_engine() ops_server = ops.OpsServer() diff --git a/sahara/service/ops.py b/sahara/service/ops.py index a652774f8b..8bc83c4b2f 100644 --- a/sahara/service/ops.py +++ b/sahara/service/ops.py @@ -61,7 +61,7 @@ class LocalOps(object): def terminate_cluster(self, cluster_id): context.spawn("cluster-terminating-%s" % cluster_id, - _terminate_cluster, cluster_id) + terminate_cluster, cluster_id) def run_edp_job(self, job_execution_id): context.spawn("Starting Job Execution %s" % job_execution_id, @@ -100,7 +100,7 @@ class OpsServer(rpc_utils.RPCServer): _provision_scaled_cluster(cluster_id, node_group_id_map) def terminate_cluster(self, cluster_id): - _terminate_cluster(cluster_id) + terminate_cluster(cluster_id) def run_edp_job(self, job_execution_id): _run_edp_job(job_execution_id) @@ -246,7 +246,7 @@ def _provision_scaled_cluster(cluster_id, node_group_id_map): @ops_error_handler -def _terminate_cluster(cluster_id): +def terminate_cluster(cluster_id): ctx = context.ctx() cluster = conductor.cluster_get(ctx, cluster_id) plugin = plugin_base.PLUGINS.get_plugin(cluster.plugin_name) diff --git a/sahara/service/periodic.py b/sahara/service/periodic.py index 0df2b068e5..1288aac038 100644 --- a/sahara/service/periodic.py +++ b/sahara/service/periodic.py @@ -25,8 +25,8 @@ from sahara.i18n import _LI from sahara.openstack.common import log from sahara.openstack.common import periodic_task from sahara.openstack.common import threadgroup -from sahara.service import api from sahara.service.edp import job_manager +from sahara.service import ops from sahara.service import trusts from sahara.utils import edp from sahara.utils import proxy as p @@ -110,7 +110,7 @@ def _make_periodic_tasks(): {'cluster': cluster.name, 'id': cluster.id}) try: - api.terminate_cluster(cluster.id) + ops.terminate_cluster(cluster.id) except Exception as e: LOG.info(_LI('Failed to terminate transient cluster ' '%(cluster)s with id %(id)s: %(error)s.'), diff --git a/sahara/tests/unit/service/test_ops.py b/sahara/tests/unit/service/test_ops.py index 69cb5a134d..76e40507af 100644 --- a/sahara/tests/unit/service/test_ops.py +++ b/sahara/tests/unit/service/test_ops.py @@ -113,7 +113,7 @@ class TestOPS(base.SaharaTestCase): base_plugins.PLUGINS.get_plugin.return_value = FakePlugin() ops.INFRA = FakeINFRA() ops.conductor = FakePlugin() - ops._terminate_cluster('123') + ops.terminate_cluster('123') # checking that order of calls is right self.assertEqual(['on_terminate_cluster', 'shutdown_cluster', 'cluster_destroy'], self.SEQUENCE, diff --git a/sahara/tests/unit/service/test_periodic.py b/sahara/tests/unit/service/test_periodic.py index 7614c9f7b3..303dc462fd 100644 --- a/sahara/tests/unit/service/test_periodic.py +++ b/sahara/tests/unit/service/test_periodic.py @@ -52,7 +52,7 @@ class TestPeriodicBack(base.SaharaWithDbTestCase): mock.call(u'3')]) @mock.patch('oslo.utils.timeutils.utcnow') - @mock.patch('sahara.service.api.terminate_cluster') + @mock.patch('sahara.service.ops.terminate_cluster') def test_cluster_terminate(self, terminate_cluster, utcnow): utcnow.return_value = datetime.datetime(2005, 2, 1, 0, 0) @@ -84,7 +84,7 @@ class TestPeriodicBack(base.SaharaWithDbTestCase): terminate_cluster.assert_has_calls([mock.call(u'1')]) @mock.patch('oslo.utils.timeutils.utcnow') - @mock.patch('sahara.service.api.terminate_cluster') + @mock.patch('sahara.service.ops.terminate_cluster') def test_cluster_not_killed_too_early(self, terminate_cluster, utcnow): utcnow.return_value = datetime.datetime(2005, 2, 1, second=0) @@ -97,7 +97,7 @@ class TestPeriodicBack(base.SaharaWithDbTestCase): self.assertEqual(terminate_cluster.call_count, 0) @mock.patch('oslo.utils.timeutils.utcnow') - @mock.patch('sahara.service.api.terminate_cluster') + @mock.patch('sahara.service.ops.terminate_cluster') def test_cluster_killed_in_time(self, terminate_cluster, utcnow): utcnow.return_value = datetime.datetime(2005, 2, 1, second=0)