diff --git a/sahara/resources/instance.heat b/sahara/resources/instance.heat index b8cd80b0..904d0180 100644 --- a/sahara/resources/instance.heat +++ b/sahara/resources/instance.heat @@ -4,6 +4,7 @@ "name" : "%(instance_name)s", "flavor" : "%(flavor_id)s", "image" : "%(image_id)s", + "admin_user": "%(image_username)s", %(network_interfaces)s %(key_name)s %(scheduler_hints)s diff --git a/sahara/service/direct_engine.py b/sahara/service/direct_engine.py index f1856ba7..19cf0052 100644 --- a/sahara/service/direct_engine.py +++ b/sahara/service/direct_engine.py @@ -35,10 +35,6 @@ LOG = logging.getLogger(__name__) class DirectEngine(e.Engine): - def get_node_group_image_username(self, node_group): - image_id = node_group.get_image_id() - return nova.client().images.get(image_id).username - def create_cluster(self, cluster): ctx = context.ctx() try: diff --git a/sahara/service/engine.py b/sahara/service/engine.py index 8cf9cc30..3d1a4dde 100644 --- a/sahara/service/engine.py +++ b/sahara/service/engine.py @@ -25,6 +25,7 @@ from sahara import context from sahara.openstack.common import log as logging from sahara.service import networks from sahara.utils import general as g +from sahara.utils.openstack import nova from sahara.utils import remote @@ -46,9 +47,9 @@ class Engine: def shutdown_cluster(self, cluster): pass - @abc.abstractmethod def get_node_group_image_username(self, node_group): - pass + image_id = node_group.get_image_id() + return nova.client().images.get(image_id).username def _await_networks(self, cluster, instances): if not instances: diff --git a/sahara/service/heat_engine.py b/sahara/service/heat_engine.py index 12ffc16b..c6c73935 100644 --- a/sahara/service/heat_engine.py +++ b/sahara/service/heat_engine.py @@ -30,13 +30,8 @@ conductor = c.API CONF = cfg.CONF LOG = logging.getLogger(__name__) -CLOUD_INIT_USERNAME = 'ec2-user' - class HeatEngine(e.Engine): - def get_node_group_image_username(self, node_group): - return CLOUD_INIT_USERNAME - def create_cluster(self, cluster): ctx = context.ctx() diff --git a/sahara/tests/integration/configs/config.py b/sahara/tests/integration/configs/config.py index 1bf221f8..fe80b960 100644 --- a/sahara/tests/integration/configs/config.py +++ b/sahara/tests/integration/configs/config.py @@ -168,8 +168,6 @@ VANILLA_CONFIG_OPTS = [ 'image. If you do not specify image related parameters, ' 'then image for cluster creation will be chosen by ' 'tag "sahara_i_tests".'), - cfg.StrOpt('SSH_USERNAME', - help='Username to get cluster node with SSH.'), cfg.StrOpt('HADOOP_VERSION', default='1.2.1', help='Version of Hadoop.'), @@ -242,8 +240,6 @@ VANILLA_TWO_CONFIG_OPTS = [ 'image. If you do not specify image related parameters, ' 'then image for cluster creation will be chosen by ' 'tag "savanna_i_tests".'), - cfg.StrOpt('SSH_USERNAME', - help='Username to get cluster node with SSH.'), cfg.StrOpt('HADOOP_VERSION', default='2.3.0', help='Version of Hadoop.'), @@ -313,8 +309,6 @@ HDP_CONFIG_OPTS = [ 'image. If you do not specify image related parameters, ' 'then image for cluster creation will be chosen by ' 'tag "sahara_i_tests".'), - cfg.StrOpt('SSH_USERNAME', - help='Username to get cluster node with SSH.'), cfg.ListOpt('MASTER_NODE_PROCESSES', default=['JOBTRACKER', 'NAMENODE', 'SECONDARY_NAMENODE', 'GANGLIA_SERVER', 'NAGIOS_SERVER', @@ -406,9 +400,6 @@ HDP2_CONFIG_OPTS = [ 'image. If you do not specify image related parameters, ' 'then image for cluster creation will be chosen by ' 'tag "sahara_i_tests".'), - cfg.StrOpt('SSH_USERNAME', - default=None, - help='Username to get cluster node with SSH.'), cfg.ListOpt('MASTER_NODE_PROCESSES', default=['NAMENODE', 'SECONDARY_NAMENODE', 'ZOOKEEPER_SERVER', 'AMBARI_SERVER', 'HISTORYSERVER', 'RESOURCEMANAGER', diff --git a/sahara/tests/integration/configs/itest.conf.sample-full b/sahara/tests/integration/configs/itest.conf.sample-full index 066433cd..cb94dcd8 100644 --- a/sahara/tests/integration/configs/itest.conf.sample-full +++ b/sahara/tests/integration/configs/itest.conf.sample-full @@ -131,10 +131,6 @@ #IMAGE_TAG = -# Username to get cluster node with SSH (string value) -#SSH_USERNAME = - - # Version of Hadoop (string value) #HADOOP_VERSION = '1.2.1' diff --git a/sahara/tests/integration/tests/base.py b/sahara/tests/integration/tests/base.py index 010f6f00..f83bc557 100644 --- a/sahara/tests/integration/tests/base.py +++ b/sahara/tests/integration/tests/base.py @@ -414,11 +414,7 @@ class ITestCase(testcase.WithAttributes, testtools.TestCase): def try_get_image_id_and_ssh_username(parameter, value): try: - if not plugin_config.SSH_USERNAME: - return image.id, image.metadata[imgs.PROP_USERNAME] - - else: - return image.id, plugin_config.SSH_USERNAME + return image.id, image.metadata[imgs.PROP_USERNAME] except KeyError: with excutils.save_and_reraise_exception(): @@ -479,11 +475,7 @@ class ITestCase(testcase.WithAttributes, testtools.TestCase): image.metadata.get(imgs.PROP_TAG + ( '%s' % plugin_config.PLUGIN_NAME))): try: - if not plugin_config.SSH_USERNAME: - return image.id, image.metadata[imgs.PROP_USERNAME] - - else: - return image.id, plugin_config.SSH_USERNAME + return image.id, image.metadata[imgs.PROP_USERNAME] except KeyError: with excutils.save_and_reraise_exception(): diff --git a/sahara/tests/unit/resources/test_serialize_resources_aa.heat b/sahara/tests/unit/resources/test_serialize_resources_aa.heat index c57888b5..942ca779 100644 --- a/sahara/tests/unit/resources/test_serialize_resources_aa.heat +++ b/sahara/tests/unit/resources/test_serialize_resources_aa.heat @@ -22,6 +22,7 @@ "name" : "cluster-worker-001", "flavor" : "42", "image" : "1", + "admin_user": "root", "networks" : [{ "port" : { "Ref" : "cluster-worker-001-port" }}], "key_name" : "user_key", "user_data": { @@ -48,6 +49,7 @@ "name" : "cluster-worker-002", "flavor" : "42", "image" : "1", + "admin_user": "root", "networks" : [{ "port" : { "Ref" : "cluster-worker-002-port" }}], "key_name" : "user_key", "scheduler_hints" : {"different_host": [{"Ref": "cluster-worker-001"}]}, @@ -75,6 +77,7 @@ "name" : "cluster-master-001", "flavor" : "42", "image" : "1", + "admin_user": "root", "networks" : [{ "port" : { "Ref" : "cluster-master-001-port" }}], "key_name" : "user_key", "user_data": { diff --git a/sahara/tests/unit/resources/test_serialize_resources_use_neutron.heat b/sahara/tests/unit/resources/test_serialize_resources_use_neutron.heat index cf46dc51..a320e41c 100644 --- a/sahara/tests/unit/resources/test_serialize_resources_use_neutron.heat +++ b/sahara/tests/unit/resources/test_serialize_resources_use_neutron.heat @@ -22,6 +22,7 @@ "name" : "cluster-worker-001", "flavor" : "42", "image" : "1", + "admin_user": "root", "networks" : [{ "port" : { "Ref" : "cluster-worker-001-port" }}], "key_name" : "user_key", "user_data": { @@ -78,6 +79,7 @@ "name" : "cluster-master-001", "flavor" : "42", "image" : "1", + "admin_user": "root", "networks" : [{ "port" : { "Ref" : "cluster-master-001-port" }}], "key_name" : "user_key", "user_data": { diff --git a/sahara/tests/unit/resources/test_serialize_resources_use_nn_with_autoassignment.heat b/sahara/tests/unit/resources/test_serialize_resources_use_nn_with_autoassignment.heat index 0f0518e2..9c3cf387 100644 --- a/sahara/tests/unit/resources/test_serialize_resources_use_nn_with_autoassignment.heat +++ b/sahara/tests/unit/resources/test_serialize_resources_use_nn_with_autoassignment.heat @@ -9,6 +9,7 @@ "name" : "cluster-worker-001", "flavor" : "42", "image" : "1", + "admin_user": "root", "key_name" : "user_key", "user_data": { "Fn::Join" : ["\n", ["line2", "line3"]] @@ -51,6 +52,7 @@ "name" : "cluster-master-001", "flavor" : "42", "image" : "1", + "admin_user": "root", "key_name" : "user_key", "user_data": { "Fn::Join" : ["\n", ["line1", "line2"]] diff --git a/sahara/tests/unit/resources/test_serialize_resources_use_nn_without_autoassignment.heat b/sahara/tests/unit/resources/test_serialize_resources_use_nn_without_autoassignment.heat index 1f96c710..6883b665 100644 --- a/sahara/tests/unit/resources/test_serialize_resources_use_nn_without_autoassignment.heat +++ b/sahara/tests/unit/resources/test_serialize_resources_use_nn_without_autoassignment.heat @@ -22,6 +22,7 @@ "name" : "cluster-worker-001", "flavor" : "42", "image" : "1", + "admin_user": "root", "key_name" : "user_key", "user_data": { "Fn::Join" : ["\n", ["line2", "line3"]] @@ -77,6 +78,7 @@ "name" : "cluster-master-001", "flavor" : "42", "image" : "1", + "admin_user": "root", "key_name" : "user_key", "user_data": { "Fn::Join" : ["\n", ["line1", "line2"]] diff --git a/sahara/tests/unit/utils/test_heat.py b/sahara/tests/unit/utils/test_heat.py index 9acda51a..200e9df6 100644 --- a/sahara/tests/unit/utils/test_heat.py +++ b/sahara/tests/unit/utils/test_heat.py @@ -78,10 +78,12 @@ class TestClusterTemplate(base.SaharaWithDbTestCase): def _make_node_groups(self, floating_ip_pool=None): ng1 = tu.make_ng_dict('master', 42, ['namenode'], 1, floating_ip_pool=floating_ip_pool, image_id=None, - volumes_per_node=0, volumes_size=0, id=1) + volumes_per_node=0, volumes_size=0, id=1, + image_username='root') ng2 = tu.make_ng_dict('worker', 42, ['datanode'], 1, floating_ip_pool=floating_ip_pool, image_id=None, - volumes_per_node=2, volumes_size=10, id=2) + volumes_per_node=2, volumes_size=10, id=2, + image_username='root') return ng1, ng2 def _make_cluster(self, mng_network, ng1, ng2): @@ -178,10 +180,12 @@ class TestClusterTemplate(base.SaharaWithDbTestCase): ng1 = tu.make_ng_dict('master', 42, ['namenode'], 1, floating_ip_pool='floating', image_id=None, - volumes_per_node=0, volumes_size=0, id=1) + volumes_per_node=0, volumes_size=0, id=1, + image_username='root') ng2 = tu.make_ng_dict('worker', 42, ['datanode'], 2, floating_ip_pool='floating', image_id=None, - volumes_per_node=0, volumes_size=0, id=2) + volumes_per_node=0, volumes_size=0, id=2, + image_username='root') cluster = tu.create_cluster("cluster", "tenant1", "general", "1.2.1", [ng1, ng2], user_keypair_id='user_key', diff --git a/sahara/utils/openstack/heat.py b/sahara/utils/openstack/heat.py index 64b83933..85a0ef75 100644 --- a/sahara/utils/openstack/heat.py +++ b/sahara/utils/openstack/heat.py @@ -168,6 +168,7 @@ class ClusterTemplate(object): fields = {'instance_name': inst_name, 'flavor_id': ng.flavor_id, 'image_id': ng.get_image_id(), + 'image_username': ng.image_username, 'network_interfaces': nets, 'key_name': key_name, 'userdata': _prepare_userdata(userdata),