diff options
author | Hong Guan <hg4105@att.com> | 2019-05-13 13:33:55 -0400 |
---|---|---|
committer | Hong Guan <hg4105@att.com> | 2019-05-13 13:33:55 -0400 |
commit | 906f5e2dc9b12074a12b69cc874056ef4a185dcc (patch) | |
tree | cb08cb20699df60774e894ca9601b8a88855c1be | |
parent | 0dc5f5a63db8cdacd39dbc3aefa0b22698154e27 (diff) |
Enhance Helm Plugindublin
Change-Id: I82fea00651d726147276e0bba378f3b76ebbd4e6
Issue-ID: CCSDK-1330
Signed-off-by: Hong Guan <hg4105@att.com>
-rw-r--r-- | helm/helm-type.yaml | 81 | ||||
-rw-r--r-- | helm/plugin/tasks.py | 321 | ||||
-rw-r--r-- | helm/plugin/tests/blueprint/blueprint.yaml | 31 | ||||
-rw-r--r-- | helm/plugin/tests/blueprint/plugin/test_plugin.yaml | 42 | ||||
-rw-r--r-- | helm/plugin/tests/test_plugin.py | 34 | ||||
-rw-r--r-- | helm/plugin/workflows.py | 42 | ||||
-rw-r--r-- | helm/pom.xml | 2 | ||||
-rw-r--r-- | helm/setup.py | 2 |
8 files changed, 338 insertions, 217 deletions
diff --git a/helm/helm-type.yaml b/helm/helm-type.yaml index 6ba9602..b404f7f 100644 --- a/helm/helm-type.yaml +++ b/helm/helm-type.yaml @@ -19,31 +19,31 @@ plugins: helm-plugin: executor: central_deployment_agent package_name: helm - package_version: 4.0.0 + package_version: 4.0.1 node_types: onap.nodes.component: derived_from: cloudify.nodes.Root properties: - tiller-server-ip: + tiller_ip: description: IP of tiller server type: string - tiller-server-port: + tiller_port: default: local description: Port of tiller server type: string - chart-repo-url: + chart_repo_url: default: local description: helm chart repo url type: string - component-name: + component_name: description: onap component string type: string - chart-version: + chart_version: description: helm chart version type: string - config-dir: + config_dir: description: config file dir default: '/opt/manager/resources/' type: string @@ -51,21 +51,24 @@ node_types: description: k8s namespace default: onap config: - description: String format config file + description: json object string type: string default: '' - config-url: - description: String format config file url + config_url: + description: config file url, supports multiple urls seperated by commas type: string default: '' - config-format: - description: String format config file format + config_format: + description: config file format - json or yaml type: string - default: 'json' - runtime-config: + default: 'yaml' + runtime_config: + default: '' + description: json object string, runtime config generate from other nodes. + config_set: default: '' - description: String format json object. To save the runtime config generate from other nodes. - tls-enable: + description: json object string for supporting helm --set option. + tls_enable: description: enable helm TSL type: boolean default: false @@ -81,23 +84,18 @@ node_types: description: value of key.pem type: string default: '' - stable-repo-url: + stable_repo_url: description: URL for stable repository type: string default: 'https://kubernetes-charts.storage.googleapis.com' - - # This part should handel by Blueprint not plugin - # the default docker values points to ONAP nexus3 docker repo. - # If need point to other private docker repo you can overrite it in blueprint node templates . -# docker-server: -# description: Private Docker Registry FQDN. -# default: nexus3.onap.org:10001 -# docker-username: -# description: Docker username. -# default: docker -# docker-password: -# description: Docker password. -# default: docker + repo_user: + description: chart repo user name + type: string + default: '' + repo_user_password: + description: chart repo user password + type: string + default: '' interfaces: cloudify.interfaces.lifecycle: @@ -115,19 +113,28 @@ workflows: parameters: node_instance_id: description: The id of the node-instance that you want to modify. - config_json: - description: The changes to the new config json + config_set: + description: set option string + default: '' + config: + description: json object string default: '' config_url: - description: The config input url + description: config input url, supports multiple urls seperated by commas default: '' config_format: - description: The config url input format - default: 'json' - chartVersion: + description: config input file format + default: 'yaml' + chart_version: description: chart version - chartRepo: + chart_repo_url: description: chart repo url + repo_user: + description: chart repo user name + default: '' + repo_user_password: + description: chart repo user password + default: '' rollback: mapping: helm-plugin.plugin.workflows.rollback parameters: diff --git a/helm/plugin/tasks.py b/helm/plugin/tasks.py index 7cb9147..c0e8921 100644 --- a/helm/plugin/tasks.py +++ b/helm/plugin/tasks.py @@ -86,11 +86,11 @@ def configure_admin_conf(): def get_current_helm_value(chart_name): - tiller_host = str(ctx.node.properties['tiller-server-ip']) + ':' + str( - ctx.node.properties['tiller-server-port']) - config_dir_root = str(ctx.node.properties['config-dir']) + tiller_host = str(ctx.node.properties['tiller_ip']) + ':' + str( + ctx.node.properties['tiller_port']) + config_dir_root = str(ctx.node.properties['config_dir']) config_dir = config_dir_root + str(ctx.deployment.id) + '/' - if str_to_bool(ctx.node.properties['tls-enable']): + if str_to_bool(ctx.node.properties['tls_enable']): getValueCommand = subprocess.Popen( ["helm", "get", "values", "-a", chart_name, '--host', tiller_host, '--tls', '--tls-ca-cert', config_dir + 'ca.cert.pem', @@ -108,11 +108,11 @@ def get_current_helm_value(chart_name): def get_helm_history(chart_name): - tiller_host = str(ctx.node.properties['tiller-server-ip']) + ':' + str( - ctx.node.properties['tiller-server-port']) - config_dir_root = str(ctx.node.properties['config-dir']) + tiller_host = str(ctx.node.properties['tiller_ip']) + ':' + str( + ctx.node.properties['tiller_port']) + config_dir_root = str(ctx.node.properties['config_dir']) config_dir = config_dir_root + str(ctx.deployment.id) + '/' - if str_to_bool(ctx.node.properties['tls-enable']): + if str_to_bool(ctx.node.properties['tls_enable']): getHistoryCommand = subprocess.Popen( ["helm", "history", chart_name, '--host', tiller_host, '--tls', '--tls-ca-cert', config_dir + 'ca.cert.pem', '--tls-cert', @@ -131,20 +131,9 @@ def get_helm_history(chart_name): ctx.instance.runtime_properties['helm-history'] = history_start_output -def mergedict(dict1, dict2): - for key in dict2.keys(): - if key not in dict1.keys(): - dict1[key] = dict2[key] - else: - if type(dict1[key]) == dict and type(dict2[key]) == dict: - mergedict(dict1[key], dict2[key]) - else: - dict1[key] = dict2[key] - - def tls(): - if str_to_bool(ctx.node.properties['tls-enable']): - config_dir_root = str(ctx.node.properties['config-dir']) + if str_to_bool(ctx.node.properties['tls_enable']): + config_dir_root = str(ctx.node.properties['config_dir']) config_dir = config_dir_root + str(ctx.deployment.id) + '/' tls_command = ' --tls --tls-ca-cert ' + config_dir + 'ca.cert.pem ' \ '--tls-cert ' + \ @@ -158,8 +147,8 @@ def tls(): def tiller_host(): tiller_host = ' --host ' + str( - ctx.node.properties['tiller-server-ip']) + ':' + str( - ctx.node.properties['tiller-server-port']) + ' ' + ctx.node.properties['tiller_ip']) + ':' + str( + ctx.node.properties['tiller_port']) + ' ' ctx.logger.debug(tiller_host) return tiller_host @@ -174,30 +163,132 @@ def str_to_bool(s): raise False +def get_config_json(config_json, config_path, config_opt_f, config_file_nm): + config_obj = {} + config_obj = json.loads(config_json) + config_file = config_path + config_file_nm + ".yaml" + gen_config_file(config_file, config_obj) + config_opt_f = config_opt_f + " -f " + config_file + return config_opt_f + + +def pop_config_info(url, config_file, f_format, repo_user, repo_user_passwd): + if url.find("@") != -1: + head, end = url.rsplit('@', 1) + head, auth = head.rsplit('//', 1) + url = head + '//' + end + username, password = auth.rsplit(':', 1) + request = urllib2.Request(url) + base64string = base64.encodestring( + '%s:%s' % (username, password)).replace('\n', '') + request.add_header("Authorization", "Basic %s" % base64string) + response = urllib2.urlopen(request) + elif repo_user != '' and repo_user_passwd != '': + request = urllib2.Request(url) + base64string = base64.b64encode('%s:%s' % (repo_user, repo_user_passwd)) + request.add_header("Authorization", "Basic %s" % base64string) + response = urllib2.urlopen(request) + else: + response = urllib2.urlopen(url) + + config_obj = {} + if f_format == 'json': + config_obj = json.load(response) + elif f_format == 'yaml': + config_obj = yaml.load(response) + else: + raise NonRecoverableError("Unable to get config input format.") + + gen_config_file(config_file, config_obj) + + +def gen_config_file(config_file, config_obj): + try: + with open(config_file, 'w') as outfile: + yaml.safe_dump(config_obj, outfile, default_flow_style=False) + except OSError as e: + if e.errno != errno.EEXIST: + raise + + +def gen_config_str(config_file, config_opt_f): + try: + with open(config_file, 'w') as outfile: + yaml.safe_dump(config_opt_f, outfile, default_flow_style=False) + except OSError as e: + if e.errno != errno.EEXIST: + raise + + +def get_rem_config(config_url, config_input_format, config_path, config_opt_f, config_file_nm, repo_user, repo_user_passwd): + ctx.logger.debug("config_url=" + config_url) + f_cnt = 0 + # urls = config_url.split() + urls = [x.strip() for x in config_url.split(',')] + if len(urls) > 1: + for url in urls: + f_cnt = f_cnt + 1 + config_file = config_path + config_file_nm + str(f_cnt) + ".yaml" + pop_config_info(url, config_file, config_input_format, repo_user, repo_user_passwd) + config_opt_f = config_opt_f + " -f " + config_file + else: + config_file = config_path + config_file_nm + ".yaml" + pop_config_info(config_url, config_file, config_input_format, repo_user, repo_user_passwd) + config_opt_f = config_opt_f + " -f " + config_file + + return config_opt_f + + +def get_config_str(config_file): + if os.path.isfile(config_file): + with open(config_file, 'r') as config_f: + return config_f.read().replace('\n', '') + return '' + + +def opt(config_file): + opt_str = get_config_str(config_file) + if opt_str != '': + return opt_str.replace("'", "") + return opt_str + +def repo(repo_url, repo_user, repo_user_passwd): + if repo_user != '' and repo_user_passwd != '' and repo_url.find("@") == -1: + proto, ip = repo_url.rsplit('//', 1) + return proto + '//' + repo_user + ':' + repo_user_passwd + '@' + ip + else: + return repo_url + + @operation def config(**kwargs): # create helm value file on K8s master - # configPath = ctx.node.properties['config-path'] configJson = str(ctx.node.properties['config']) - configUrl = str(ctx.node.properties['config-url']) - configUrlInputFormat = str(ctx.node.properties['config-format']) - runtime_config = str(ctx.node.properties['runtime-config']) # json - componentName = ctx.node.properties['component-name'] - config_dir_root = str(ctx.node.properties['config-dir']) - stable_repo_url = str(ctx.node.properties['stable-repo-url']) + configUrl = str(ctx.node.properties['config_url']) + configUrlInputFormat = str(ctx.node.properties['config_format']) + runtime_config = str(ctx.node.properties['runtime_config']) # json + componentName = ctx.node.properties['component_name'] + config_dir_root = str(ctx.node.properties['config_dir']) + stable_repo_url = str(ctx.node.properties['stable_repo_url']) + config_opt_set = str(ctx.node.properties['config_set']) + repo_user = str(ctx.node.properties['repo_user']) + repo_user_passwd = str(ctx.node.properties['repo_user_password']) ctx.logger.debug("debug " + configJson + runtime_config) # load input config config_dir = config_dir_root + str(ctx.deployment.id) - try: - os.makedirs(config_dir) - except OSError as e: - if e.errno != errno.EEXIST: - raise + + if not os.path.exists(config_dir): + try: + os.makedirs(config_dir) + except OSError as e: + if e.errno != errno.EEXIST: + raise + ctx.logger.debug('tls-enable type ' + str( - type(str_to_bool(ctx.node.properties['tls-enable'])))) + type(str_to_bool(ctx.node.properties['tls_enable'])))) # create TLS cert files - if str_to_bool(ctx.node.properties['tls-enable']): + if str_to_bool(ctx.node.properties['tls_enable']): ctx.logger.debug('tls enable') ca_value = ctx.node.properties['ca'] cert_value = ctx.node.properties['cert'] @@ -214,51 +305,45 @@ def config(**kwargs): else: ctx.logger.debug('tls disable') - # create helm value.yaml file - configPath = config_dir_root + str( - ctx.deployment.id) + '/' + componentName + '.yaml' - ctx.logger.debug(configPath) + config_path = config_dir + '/' + componentName + '/' + ctx.logger.debug(config_path) - configObj = {} + if os.path.exists(config_path): + shutil.rmtree(config_path) + + try: + os.makedirs(config_path) + except OSError as e: + if e.errno != errno.EEXIST: + raise + + config_opt_f = "" if configJson == '' and configUrl == '': ctx.logger.debug("Will use default HELM value") elif configJson == '' and configUrl != '': - if configUrl.find("@") != -1: - head, end = configUrl.rsplit('@', 1) - head, auth = head.rsplit('//', 1) - configUrl = head + '//' + end - username, password = auth.rsplit(':', 1) - request = urllib2.Request(configUrl) - base64string = base64.encodestring( - '%s:%s' % (username, password)).replace('\n', '') - request.add_header("Authorization", "Basic %s" % base64string) - response = urllib2.urlopen(request) - else: - response = urllib2.urlopen(configUrl) - if configUrlInputFormat == 'json': - configObj = json.load(response) - elif configUrlInputFormat == 'yaml': - configObj = yaml.load(response) - else: - raise NonRecoverableError("Unable to get config input format.") + config_opt_f = get_rem_config(configUrl, configUrlInputFormat, config_path, config_opt_f, "rc", repo_user, repo_user_passwd) elif configJson != '' and configUrl == '': - configObj = json.loads(configJson) + config_opt_f = get_config_json(configJson, config_path, config_opt_f, "lc") else: - raise NonRecoverableError("Unable to get Json config input") + raise NonRecoverableError("Unable to get config input") - # load runtime config ctx.logger.debug("debug check runtime config") if runtime_config == '': ctx.logger.debug("there is no runtime config value") else: - runtime_config_obj = json.loads(runtime_config) - mergedict(configObj, runtime_config_obj) + config_opt_f = get_config_json(runtime_config, config_path, config_opt_f, "rt") + + if configUrl != '' or configJson != '' or runtime_config != '': + config_file = config_path + ".config_file" + gen_config_str(config_file, config_opt_f) - with open(configPath, 'w') as outfile: - yaml.safe_dump(configObj, outfile, default_flow_style=False) + if config_opt_set != '': + config_file = config_path + ".config_set" + config_opt_set = " --set " + config_opt_set + gen_config_str(config_file, config_opt_set) output = execute_command( - 'helm init --client-only --stable-repo-url ' + stable_repo_url) + 'helm init --client-only --stable-repo-url ' + repo(stable_repo_url, repo_user, repo_user_passwd)) if output == False: raise NonRecoverableError("helm init failed") @@ -267,27 +352,23 @@ def config(**kwargs): def start(**kwargs): # install the ONAP Helm chart # get properties from node - chartRepo = ctx.node.properties['chart-repo-url'] - componentName = ctx.node.properties['component-name'] - chartVersion = ctx.node.properties['chart-version'] - config_dir_root = str(ctx.node.properties['config-dir']) - configPath = config_dir_root + str( - ctx.deployment.id) + '/' + componentName + '.yaml' + repo_user = str(ctx.node.properties['repo_user']) + repo_user_passwd = str(ctx.node.properties['repo_user_password']) + chartRepo = ctx.node.properties['chart_repo_url'] + componentName = ctx.node.properties['component_name'] + chartVersion = str(ctx.node.properties['chart_version']) + config_dir_root = str(ctx.node.properties['config_dir']) namespace = ctx.node.properties['namespace'] - configJson = str(ctx.node.properties['config']) - configUrl = str(ctx.node.properties['config-url']) - runtimeconfigJson = str(ctx.node.properties['runtime-config']) - chart = chartRepo + "/" + componentName + "-" + chartVersion + ".tgz" + config_path = config_dir_root + str( + ctx.deployment.id) + '/' + componentName + '/' + chart = chartRepo + "/" + componentName + "-" + str(chartVersion) + ".tgz" chartName = namespace + "-" + componentName - - if configJson == '' and runtimeconfigJson == '' and configUrl == '': - installCommand = 'helm install ' + chart + ' --name ' + chartName + \ - ' --namespace ' + namespace + tiller_host() + tls() - else: - installCommand = 'helm install ' + chart + ' --name ' + chartName + \ - ' --namespace ' + namespace + ' -f ' + configPath + \ - tiller_host() + tls() + config_file = config_path + ".config_file" + config_set = config_path + ".config_set" + installCommand = 'helm install ' + repo(chart, repo_user, repo_user_passwd) + ' --name ' + chartName + \ + ' --namespace ' + namespace + opt(config_file) + \ + opt(config_set) + tiller_host() + tls() output = execute_command(installCommand) if output == False: @@ -305,44 +386,66 @@ def stop(**kwargs): # configure_admin_conf() # get properties from node namespace = ctx.node.properties['namespace'] - component = ctx.node.properties['component-name'] + component = ctx.node.properties['component_name'] chartName = namespace + "-" + component - config_dir_root = str(ctx.node.properties['config-dir']) + config_dir_root = str(ctx.node.properties['config_dir']) # Delete helm chart command = 'helm delete --purge ' + chartName + tiller_host() + tls() output = execute_command(command) if output == False: raise NonRecoverableError("helm delete failed") - config_file = config_dir_root + str( - ctx.deployment.id) + '/' + component + '.yaml' - os.remove(config_file) + config_path = config_dir_root + str( + ctx.deployment.id) + '/' + component + + if os.path.exists(config_path): + shutil.rmtree(config_path) @operation def upgrade(**kwargs): - # upgrade the helm chart - componentName = ctx.node.properties['component-name'] - config_dir_root = str(ctx.node.properties['config-dir']) - configPath = config_dir_root + str( - ctx.deployment.id) + '/' + componentName + '.yaml' - componentName = ctx.node.properties['component-name'] + config_dir_root = str(ctx.node.properties['config_dir']) + componentName = ctx.node.properties['component_name'] namespace = ctx.node.properties['namespace'] + repo_user = kwargs['repo_user'] + repo_user_passwd = kwargs['repo_user_passwd'] configJson = kwargs['config'] chartRepo = kwargs['chart_repo'] chartVersion = kwargs['chart_version'] - - ctx.logger.debug('debug ' + str(configJson)) + config_set = kwargs['config_set'] + config_json = kwargs['config_json'] + config_url = kwargs['config_url'] + config_format = kwargs['config_format'] + config_path = config_dir_root + str( + ctx.deployment.id) + '/' + componentName + '/' + + # ctx.logger.debug('debug ' + str(configJson)) chartName = namespace + "-" + componentName chart = chartRepo + "/" + componentName + "-" + chartVersion + ".tgz" - if str(configJson) == '': - upgradeCommand = 'helm upgrade ' + chartName + ' ' + chart + \ - tiller_host() + tls() + + config_opt_f = "" + if config_json == '' and config_url == '': + ctx.logger.debug("Will use default HELM values") + elif config_json == '' and config_url != '': + config_opt_f = get_rem_config(config_url, config_format, config_path, config_opt_f, "ru", repo_user, repo_user_passwd) + elif config_json != '' and config_url == '': + config_opt_f = get_config_json(config_json, config_path, config_opt_f, "lu") else: - with open(configPath, 'w') as outfile: - yaml.safe_dump(configJson, outfile, default_flow_style=False) - # configure_admin_conf() - upgradeCommand = 'helm upgrade ' + chartName + ' ' + chart + ' -f ' + \ - configPath + tiller_host() + tls() + raise NonRecoverableError("Unable to get upgrade config input") + + config_upd = "" + if config_url != '' or config_json != '': + config_upd = config_path + ".config_upd" + gen_config_str(config_upd, config_opt_f) + + config_upd_set = "" + if config_set != '': + config_upd_set = config_path + ".config_upd_set" + config_opt_set = " --set " + config_set + gen_config_str(config_upd_set, config_opt_set) + + upgradeCommand = 'helm upgrade ' + chartName + ' ' + repo(chart, repo_user, repo_user_passwd) + opt(config_upd) + \ + opt(config_upd_set) + tiller_host() + tls() + output = execute_command(upgradeCommand) if output == False: return ctx.operation.retry( @@ -355,7 +458,7 @@ def upgrade(**kwargs): @operation def rollback(**kwargs): # rollback to some revision - componentName = ctx.node.properties['component-name'] + componentName = ctx.node.properties['component_name'] namespace = ctx.node.properties['namespace'] revision = kwargs['revision'] # configure_admin_conf() @@ -371,7 +474,7 @@ def rollback(**kwargs): @operation def status(**kwargs): - componentName = ctx.node.properties['component-name'] + componentName = ctx.node.properties['component_name'] namespace = ctx.node.properties['namespace'] chartName = namespace + "-" + componentName diff --git a/helm/plugin/tests/blueprint/blueprint.yaml b/helm/plugin/tests/blueprint/blueprint.yaml index 9636991..9a96910 100644 --- a/helm/plugin/tests/blueprint/blueprint.yaml +++ b/helm/plugin/tests/blueprint/blueprint.yaml @@ -30,6 +30,8 @@ inputs: default: '' config-url: default: '' + config-set: + default: '' config-format: default: 'json' tls-enable: @@ -38,6 +40,12 @@ inputs: config-dir: type: string default: './' + repo-user: + type: string + default: '' + repo-user-password: + type: string + default: '' stable-repo-url: type: string default: 'http://0.0.0.0/stable' @@ -49,21 +57,24 @@ node_templates: # using base cloudify type type: onap.nodes.component properties: - tiller-server-ip: { get_input: tiller-server-ip } - tiller-server-port: { get_input: tiller-server-port } - component-name: test_node - chart-repo-url: { get_input: chart-repo-url } - chart-version: { get_input: chart-version } + tiller_ip: { get_input: tiller-server-ip } + tiller_port: { get_input: tiller-server-port } + component_name: test_node + chart_repo_url: { get_input: chart-repo-url } + chart_version: { get_input: chart-version } namespace: { get_input: namespace } config: { get_input: jsonConfig} - config-url: { get_input: config-url} - config-format: { get_input: config-format} - tls-enable: { get_input: tls-enable} + config_set: { get_input: config-set} + config_url: { get_input: config-url} + repo_user: { get_input: repo-user} + repo_user_password: { get_input: repo-user-password} + config_format: { get_input: config-format} + tls_enable: { get_input: tls-enable} ca: { get_secret: ca_value} cert: { get_secret: cert_value} key: { get_secret: key_value} - config-dir: { get_input: config-dir} - stable-repo-url: { get_input: stable-repo-url} + config_dir: { get_input: config-dir} + stable_repo_url: { get_input: stable-repo-url} outputs: # example output the could be used to simplify assertions by test diff --git a/helm/plugin/tests/blueprint/plugin/test_plugin.yaml b/helm/plugin/tests/blueprint/plugin/test_plugin.yaml index e3b257e..22346a2 100644 --- a/helm/plugin/tests/blueprint/plugin/test_plugin.yaml +++ b/helm/plugin/tests/blueprint/plugin/test_plugin.yaml @@ -26,24 +26,24 @@ node_types: onap.nodes.component: derived_from: cloudify.nodes.Root properties: - tiller-server-ip: + tiller_ip: description: IP of tiller server type: string - tiller-server-port: + tiller_port: default: local description: Port of tiller server type: string - chart-repo-url: + chart_repo_url: default: local description: helm chart repo url type: string - component-name: + component_name: description: onap component string type: string - chart-version: + chart_version: description: helm chart version type: string - config-dir: + config_dir: description: config file dir default: '/opt/manager/resources/' type: string @@ -54,18 +54,22 @@ node_types: description: String format config file type: string default: '' - config-url: + config_set: + description: String format config file + type: string + default: '' + config_url: description: String format config file url type: string default: '' - config-format: + config_format: description: String format config file format type: string default: 'json' - runtime-config: + runtime_config: default: '' description: String format json object. To save the runtime config generate from other nodes. - tls-enable: + tls_enable: description: enable helm TSL type: boolean default: false @@ -81,10 +85,17 @@ node_types: description: value of key.pem type: string default: '' - stable-repo-url: + stable_repo_url: description: URL for stable repository type: string default: 'https://kubernetes-charts.storage.googleapis.com' + repo_user: + type: string + default: '' + repo_user_password: + type: string + default: '' + interfaces: cloudify.interfaces.lifecycle: @@ -101,7 +112,10 @@ workflows: parameters: node_instance_id: description: The id of the node-instance that you want to modify. - config_json: + config_set: + description: The set option string + default: '' + config: description: The changes to the new config json default: '' config_url: @@ -110,9 +124,9 @@ workflows: config_format: description: The config url input format default: 'json' - chartVersion: + chart_version: description: chart version - chartRepo: + chart_repo_url: description: chart repo url rollback: mapping: helm-plugin.plugin.workflows.rollback diff --git a/helm/plugin/tests/test_plugin.py b/helm/plugin/tests/test_plugin.py index 95d9c3f..3dde089 100644 --- a/helm/plugin/tests/test_plugin.py +++ b/helm/plugin/tests/test_plugin.py @@ -125,11 +125,14 @@ class TestPlugin(unittest.TestCase): config_format = 'json' chartVersion = '2.0.0' chartRepo = 'repo' + repo_user = '' + repo_user_passwd = '' try: cfy_local.execute('upgrade', task_retries=0, - parameters={'node_instance_id': node_instance_id, 'config_json': config_json, - 'config_url': config_url, 'config_format': config_format, - 'chartVersion': chartVersion, 'chartRepo': chartRepo}) + parameters={'node_instance_id': node_instance_id, 'config': config_json, + 'config_url': config_url, 'config_format': config_format, + 'chart_version': chartVersion, 'chart_repo_url': chartRepo, + 'repo_user': repo_user, 'repo_user_password': repo_user_passwd}) self.fail('Expected exception due to operation not exist') except Exception as e: self.assertTrue('operation not available') @@ -142,11 +145,11 @@ class TestPlugin(unittest.TestCase): :rollback operation test: """ props = { - 'component-name': 'test_node', + 'component_name': 'test_node', 'namespace': 'onap', - 'tiller-server-port': '8888', - 'tiller-server-ip': '1.1.1.1', - 'tls-enable': 'false' + 'tiller_port': '8888', + 'tiller_ip': '1.1.1.1', + 'tls_enable': 'false' } args = {'revision': '1'} mock_ctx = MockCloudifyContext(node_id='test_node_id', node_name='test_node_name', @@ -167,20 +170,23 @@ class TestPlugin(unittest.TestCase): :upgrade operation test: """ props = { - 'component-name': 'test_node', + 'component_name': 'test_node', 'namespace': 'onap', - 'tiller-server-port': '8888', - 'tiller-server-ip': '1.1.1.1', - 'tls-enable': 'false', - 'config-dir': '/tmp' + 'tiller_port': '8888', + 'tiller_ip': '1.1.1.1', + 'tls_enable': 'false', + 'config_dir': '/tmp' } - args = {'revision': '1', 'config': '', 'chart_repo': 'repo', 'chart_version': '2'} + args = {'revision': '1', 'config': '', 'chart_repo': 'repo', 'chart_version': '2', + 'config_set': 'config_set', 'config_json': '', 'config_url': '', + 'config_format': 'format', 'repo_user': '', 'repo_user_passwd': ''} mock_ctx = MockCloudifyContext(node_id='test_node_id', node_name='test_node_name', properties=props) try: current_ctx.set(mock_ctx) with mock.patch('plugin.tasks.get_current_helm_value'): with mock.patch('plugin.tasks.get_helm_history'): - plugin.tasks.upgrade(**args) + with mock.patch('plugin.tasks.gen_config_str'): + plugin.tasks.upgrade(**args) finally: current_ctx.clear() diff --git a/helm/plugin/workflows.py b/helm/plugin/workflows.py index de5549d..be1db8d 100644 --- a/helm/plugin/workflows.py +++ b/helm/plugin/workflows.py @@ -25,8 +25,8 @@ import base64 @workflow -def upgrade(node_instance_id, config_json, config_url, config_format, - chartVersion, chartRepo, **kwargs): +def upgrade(node_instance_id, config_set, config, config_url, config_format, + chart_version, chart_repo_url, repo_user, repo_user_password, **kwargs): node_instance = ctx.get_node_instance(node_instance_id) if not node_instance_id: @@ -35,35 +35,15 @@ def upgrade(node_instance_id, config_json, config_url, config_format, node_instance_id)) kwargs = {} - if config_json == '' and config_url == '': - kwargs['config'] = config_json - elif config_json == '' and config_url != '': - if config_url.find("@") != -1: - head, end = config_url.rsplit('@', 1) - head, auth = head.rsplit('//', 1) - config_url = head + '//' + end - username, password = auth.rsplit(':', 1) - request = urllib2.Request(config_url) - base64string = base64.encodestring( - '%s:%s' % (username, password)).replace('\n', '') - request.add_header("Authorization", "Basic %s" % base64string) - response = urllib2.urlopen(request) - else: - response = urllib2.urlopen(config_url) - if config_format == 'json': - kwargs['config'] = json.load(response) - elif config_format == 'yaml': - kwargs['config'] = yaml.load(response) - else: - raise NonRecoverableError("Unable to get config input format") - elif config_json != '' and config_url == '': - kwargs['config'] = config_json - - else: - raise NonRecoverableError("Unable to get Json config input") - - kwargs['chart_version'] = str(chartVersion) - kwargs['chart_repo'] = str(chartRepo) + kwargs['config'] = '' + kwargs['chart_version'] = str(chart_version) + kwargs['chart_repo'] = str(chart_repo_url) + kwargs['config_set'] = str(config_set) + kwargs['config_json'] = str(config) + kwargs['config_url'] = str(config_url) + kwargs['config_format'] = str(config_format) + kwargs['repo_user'] = str(repo_user) + kwargs['repo_user_passwd'] = str(repo_user_password) operation_args = {'operation': 'upgrade', } operation_args['kwargs'] = kwargs node_instance.execute_operation(**operation_args) diff --git a/helm/pom.xml b/helm/pom.xml index 8412b1f..3290e32 100644 --- a/helm/pom.xml +++ b/helm/pom.xml @@ -41,7 +41,7 @@ limitations under the License. <!-- path of types file itself relative to this file --> <typefile.source>helm-type.yaml</typefile.source> <!-- path, in repo, to store type file --> - <typefile.dest>type_files/helm/4.0.0/helm-type.yaml</typefile.dest> + <typefile.dest>type_files/helm/4.0.1/helm-type.yaml</typefile.dest> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <sonar.sources>.</sonar.sources> <sonar.junit.reportsPath>nosetests.xml</sonar.junit.reportsPath> diff --git a/helm/setup.py b/helm/setup.py index dc770dc..df41f23 100644 --- a/helm/setup.py +++ b/helm/setup.py @@ -24,7 +24,7 @@ setup( # Do not use underscores in the plugin name. name='helm', - version='4.0.0', + version='4.0.1', author='Nicolas Hu(AT&T)', author_email='jh245g@att.com', description='This plugin will install/uninstall/upgrade/rollback helm ' |