-
-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
313 heat files parameter #317
Conversation
test/test_helper.rb
Outdated
@@ -68,6 +68,14 @@ def array_differences(array_a, array_b) | |||
(array_a - array_b) | (array_b - array_a) | |||
end | |||
|
|||
def prefix_with_url(files, base_url) | |||
return files.map {|fname| File.join(base_url.to_s , fname)}.compact |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant return detected.
Space between { and | missing.
Space found before comma.
Space missing inside }.
response.body.must_match_schema(@create_format_files) | ||
files = response.body['files'] | ||
Fog::Logger.warning("Request processed: #{files.keys()}") | ||
assert_equal_set(["file:///code/test/requests/orchestration/local.yaml", "file:///code/test/requests/orchestration/hot_1.yaml"], files.keys()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [150/120]
Do not use parentheses for method calls with no arguments.
response = @orchestration.create_stack(args) | ||
response.body.must_match_schema(@create_format_files) | ||
files = response.body['files'] | ||
Fog::Logger.warning("Request processed: #{files.keys()}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use parentheses for method calls with no arguments.
:stack_name => "teststack_files", | ||
:template => YAML.load(open("local.yaml")), | ||
} | ||
response = @orchestration.create_stack(args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
Dir.chdir("/code/test/requests/orchestration") do | ||
args = { | ||
:stack_name => "teststack_files", | ||
:template => YAML.load(open("local.yaml")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer using YAML.safe_load over YAML.load.
it "#recurse_template" do | ||
Dir.chdir("test/requests/orchestration") do | ||
hot_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(@local_yaml) | ||
files = hot_resolver.get_files() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use parentheses for method calls with no arguments.
hot_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(@template_yaml) | ||
hot_resolver.get_file_contents(data) | ||
Fog::Logger.warning("Processed files: #{hot_resolver.files.keys()}") | ||
assert_equal_set(hot_resolver.files.keys(), expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use parentheses for method calls with no arguments.
test_cases.each {|data, expected| | ||
hot_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(@template_yaml) | ||
hot_resolver.get_file_contents(data) | ||
Fog::Logger.warning("Processed files: #{hot_resolver.files.keys()}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use parentheses for method calls with no arguments.
test_cases = @data["get_file_contents_http_template"].map{ |testcase| | ||
# [ testcase['input'], testcase['expected'] ] | ||
}.compact | ||
test_cases.each {|data, expected| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space between { and | missing.
Avoid using {...} for multi-line blocks.
|
||
it "#get_file_contents_http_template" do | ||
test_cases = @data["get_file_contents_http_template"].map{ |testcase| | ||
# [ testcase['input'], testcase['expected'] ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect indentation detected (column 4 instead of 8).
24cd567
to
e81e8f4
Compare
response.body.must_match_schema(@create_format_files) | ||
files = response.body['files'] | ||
Fog::Logger.warning("Request processed: #{files.keys}") | ||
assert_equal_set(["file:///code/test/requests/orchestration/local.yaml", "file:///code/test/requests/orchestration/hot_1.yaml"], files.keys) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [148/120]
test_cases.each do |data, expected| | ||
expected = prefix_with_url(expected, @base_url) | ||
hot_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(@template_yaml) | ||
hot_resolver.get_file_contents(data, base_url = @base_url.to_s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless assignment to variable - base_url.
[["a", "list"], {}], | ||
[{"a" => "dict", "b" => "values"}, {}], | ||
[{"type"=>"OS::Nova::Server"}, {}], | ||
[{"get_file" => "test/requests/orchestration/foo.sh", "b" => "values"}, {'test/requests/orchestration/foo.sh'=>'# Just a mock'}], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [137/120]
it "#get_file_contents_simple" do | ||
test_cases = [ | ||
["a string", {}], | ||
[["a", "list"], {}], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use %w or %W for an array of words.
assert_includes(content, "Disallow:") | ||
end | ||
|
||
it "#get_content_404" do # FIXME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary spacing detected.
if key == "type" && is_template(file_content) && !(@visited[str_url]) | ||
if is_object | ||
raise NotImplementedError | ||
template = get_template_contents( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unreachable code detected.
|
||
if is_object && object_request | ||
raise NotImplementedError | ||
file_content = object_request('GET', str_url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unreachable code detected.
|
||
# Actually processing data. | ||
if from_data.kind_of?(Hash) | ||
from_data.each do |key, value| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [34/25]
return nil, template | ||
end | ||
|
||
def get_file_contents(from_data, base_url = nil, is_object = false, object_request = nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for get_file_contents is too high. [37.56/15]
Cyclomatic complexity for get_file_contents is too high. [16/6]
Method has too many lines. [49/25]
Perceived complexity for get_file_contents is too high. [19/7]
|
||
@visited[template_file] = true | ||
Fog::Logger.warning("Template visited: #{@visited}") | ||
get_file_contents(template, base_url = template_base_url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless assignment to variable - base_url.
0101499
to
50b276f
Compare
|
||
it "#dont_modify_passed_template" do | ||
hot_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(@local_yaml) | ||
hot_resolver.get_files() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use parentheses for method calls with no arguments.
Dir.chdir(@oldcwd) | ||
end | ||
|
||
describe "success" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [86/25]
@local_yaml = YAML.safe_load(open("local.yaml")) | ||
@hot_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(@template_yaml) | ||
@base_url = URI.join("file:", File.absolute_path(".")) | ||
@base_url.host = "" # fix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary spacing detected.
require "open-uri" | ||
require "fog/orchestration/util/recursive_hot_file_loader" # FIXME: is there a better way to require this file? | ||
|
||
describe "Fog::Orchestration[:openstack] | stack requests" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [107/25]
return nil, template | ||
end | ||
|
||
def get_file_contents(from_data, base_url = nil, is_object = false, object_request = nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for get_file_contents is too high. [38.79/15]
Cyclomatic complexity for get_file_contents is too high. [17/6]
Method has too many lines. [49/25]
Perceived complexity for get_file_contents is too high. [20/7]
files = hot_resolver.get_files() | ||
if files | ||
options['files'] = files | ||
options['template'] = hot_resolver.template |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't mix key :template
with 'template'
. We should always use symbols in this context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to reassign options[:template]
? Here I believe you are actually setting it to a Hash object which is not acceptable by OpenStack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure unicity of template resources, we need to:
- convert every
type
andget_file
reference to a full URI (eg. file:/// or http:///)
On Newton I was able to create the stack referenced in the MIQ ticket using that code, but I still need to write a proper functional testsuite.
@@ -28,6 +30,14 @@ def create_stack(arg1, arg2 = nil) | |||
}.merge(arg2.nil? ? {} : arg2) | |||
end | |||
|
|||
# Eventually resolve files and update original template. | |||
hot_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(options[:template]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OpenStack accepts either options[:template]
or options[:template_url]
. So we cannot assume options[:template]
is always present. Do you want to resolve files for a template from an URL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll add support for template_url too. I need to add this to https://github.com/fog/fog-openstack/blob/master/docs/orchestration.md as it's not mentioned there.
end | ||
|
||
def get_files | ||
Fog::Logger.warning("Processing template #{@template}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why warning
? You should lower it to debug level. Should fix all warning
s in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Until in [WIP] I need warnings to show those logs. Then I'll move to debug.
|
||
def recurse_if(value) | ||
# Should I recurse into this template branch? | ||
!!(value.kind_of?(Hash) || value.kind_of?(Array)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!!
is redundant.
# XXX Protect from vanilla open-uri attacks | ||
uri_or_filename = uri_or_filename[7..-1] if uri_or_filename.start_with?("file:///") | ||
open(uri_or_filename) { |f| content = f.read } | ||
content == "Error" ? nil : content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is problematic. You are not assigning the result to anything. Besides, can content
ever be Error
?
You made a few comments but did not provide solution. It does not look like final code to be merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been told to create a [WIP] pull request to simplify code reviews.
For these lines I'd appreciate some help:
- which are some common test cases involving open-uri?
- do you have any suggestions about securing other parts of this code?
Hi @bzwei Thank you very much for your time! Consider this patch is [WIP] and has been pushed to collect code-reviews and comments. Thanks for all the ruby-related comments! If you have some implementation-related feedback or questions please let me know! |
@ioggstream Sorry, I did not realize that it is still wip. Take your time to refine and complete. I will review it more. |
@bzwei don't worry, and thank you very much for all your time! You're welcome to suggest whatever you like so that I can fine-tune the code as soon as possible! |
8ccf5ae
to
233f79e
Compare
raise NotImplementedError, "template should be Hash or String" | ||
end | ||
|
||
get_file_contents(template, base_url = template_base_url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless assignment to variable - base_url.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way to call the method looks strange. Like the bot says, remove base_url
# Normalize yaml. | ||
Fog::Logger.warning("Reingest") | ||
template = YAML.safe_load(YAML.dump(template_file)) | ||
template_base_url = base_url_for_url(normalise_file_path_to_url(Dir.pwd+"/TEMPLATE")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surrounding space missing for operator +.
@visited[template_file] = true | ||
Fog::Logger.warning("Template visited: #{@visited}") | ||
end | ||
template = YAML.load(tpl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer using YAML.safe_load over YAML.load.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seanhandley As of now, YAML.safe_load
has issues with dates. Elsewhere, fog still uses YAML.load
YAML.safe_load("heat_template_version: 2016-10-14") # Psych::DisallowedClass exception (Date)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try YAML.safe_load(tpl, [Date])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bzwei ok with YAML.safe_load(tpl, [Date])
. It shouldn't break things, right? (eg. deserializes and serializes date in the same format, ...)
if template_file.kind_of?(String) | ||
if is_template(template_file) | ||
tpl = template_file | ||
template_base_url = base_url_for_url(normalise_file_path_to_url(Dir.pwd+"/TEMPLATE")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surrounding space missing for operator +.
content | ||
end | ||
|
||
def get_template_contents(template_file, _template_url = nil, _template_object = nil, _existing = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for get_template_contents is too high. [24.35/15]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the last three arguments if they are not used at all.
end | ||
end | ||
|
||
def is_template(content) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename is_template to template?.
Fog::Logger.warning("Processing template #{@template}") | ||
_, @template = get_template_contents(@template) | ||
Fog::Logger.warning("Template processed. Populated #{@files}") | ||
return @files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant return detected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seanhandley do I always need to use implicit return in ruby?
existing=existing) | ||
rescue Exception | ||
# The initial exception gives the user better failure context. | ||
raise template_file_exc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 (not 4) spaces for indentation.
return get_template_contents(template_object=template_path, | ||
object_request=object_request, | ||
existing=existing) | ||
rescue Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid rescuing the Exception class. Perhaps you meant to rescue StandardError?
begin | ||
return get_template_contents(template_object=template_path, | ||
object_request=object_request, | ||
existing=existing) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless assignment to variable - existing. Did you mean _existing?
Surrounding space missing for operator =.
test_cases.each do |data, expected| | ||
expected = prefix_with_url(expected, @base_url) | ||
hot_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(data) | ||
files = hot_resolver.get_files() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use parentheses for method calls with no arguments.
end.compact | ||
test_cases.each do |data, expected| | ||
hot_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(data) | ||
hot_resolver.get_files() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use parentheses for method calls with no arguments.
Dir.chdir(@oldcwd) | ||
end | ||
|
||
describe "success" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [89/25]
require "open-uri" | ||
require "fog/orchestration/util/recursive_hot_file_loader" # FIXME: is there a better way to require this file? | ||
|
||
describe "Fog::Orchestration[:openstack] | stack requests" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [110/25]
@ioggstream What if downloading a resource file fails, or a local file does not exist? Should we fail the stack creation immediately because anyway it will fail at the provider side, right? |
@bzwei If a resource file can't be loaded, fog should log and raise an exception. Otherwise, heat will start processing the stack and throw the error in the response. I'm trying to test the patch inside manageiq and I'm now on both freenode#manageiq and gitter#manageiq. Ping me if you like. |
Update gem in manageiq
|
# and replaces it with :template. | ||
# see https://github.com/openstack-infra/shade/blob/master/shade/openstackcloud.py#L1201 | ||
# see https://developer.openstack.org/api-ref/orchestration/v1/index.html#create-stack | ||
hot_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest file_resolver
to better describe the purpose of the variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the resolver only when options[:files]
does not exist. In other words, no need to load files if the caller already provides them. Update the comments in https://github.com/fog/fog-openstack/pull/317/files#diff-360fd267b1a87d726bdd369c23976486R10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bzwei in shade they merge passed and retrieved :files. Without the retrieved ones the stack will fail. https://github.com/openstack-infra/shade/blob/master/shade/openstackcloud.py#L1258
# and replaces it with :template. | ||
# see https://github.com/openstack-infra/shade/blob/master/shade/openstackcloud.py#L1201 | ||
# see https://developer.openstack.org/api-ref/orchestration/v1/index.html#create-stack | ||
hot_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as for create_stack
# | ||
# This implementation just process nested templates but not resource | ||
# registries. | ||
class RecursiveHotFileLoader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic how to traverse nodes and load files seems over complicated. I have hard time to follow. Can you add comments to each method? We can remove some of them if they turn out to be straightforward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bzwei agree but:
- my first implementation was simpler
- then I preferred to mimic the more stable python implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bzwei Refactored a bit and added comments.
content | ||
end | ||
|
||
def get_template_contents(template_file, _template_url = nil, _template_object = nil, _existing = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the last three arguments if they are not used at all.
raise NotImplementedError, "template should be Hash or String" | ||
end | ||
|
||
get_file_contents(template, base_url = template_base_url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way to call the method looks strange. Like the bot says, remove base_url
elsif template_file.kind_of?(Hash) | ||
# Normalize yaml. | ||
Fog::Logger.warning("Reingest") | ||
template = YAML.safe_load(YAML.dump(template_file)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to normalize yaml? Here template_file
is already a hash, isn't it?
expected = prefix_with_url(["local.yaml", "hot_1.yaml"], @base_url) | ||
args = { | ||
:stack_name => "teststack_files", | ||
:template => YAML.load(open("local.yaml")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer using YAML.safe_load over YAML.load.
test_cases.each do |data, expected| | ||
expected = prefix_with_url(expected, @base_url) | ||
hot_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(@template_yaml) | ||
hot_resolver.get_file_contents(data, base_url = @base_url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless assignment to variable - base_url.
Dir.chdir(@oldcwd) | ||
end | ||
|
||
describe "success" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [80/25]
@data = @hot_resolver.yaml_load(open("stack_files_util_tests.yaml")) | ||
@template_yaml = @hot_resolver.yaml_load(open("template.yaml")) | ||
@local_yaml = @hot_resolver.yaml_load(open("local.yaml")) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra empty line detected at block body end.
|
||
it "#dont_modify_passed_template" do | ||
file_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(@local_yaml) | ||
file_resolver.get_files() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use parentheses for method calls with no arguments.
# get_file should not recurse hot templates. | ||
if key == "type" && template?(file_content) && !(@visited[str_url]) | ||
template = get_template_contents( | ||
template_url = str_url |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless assignment to variable - template_url. Did you mean template?
return nil, template | ||
end | ||
|
||
def get_file_contents(from_data, base_url = nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for get_file_contents is too high. [31.59/15]
Cyclomatic complexity for get_file_contents is too high. [14/6]
Method has too many lines. [36/25]
Perceived complexity for get_file_contents is too high. [15/7]
content | ||
end | ||
|
||
def get_template_contents(template_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for get_template_contents is too high. [20.81/15]
end | ||
|
||
def yaml_load(content) | ||
return YAML.load(content) if RUBY_VERSION < "2.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer using YAML.safe_load over YAML.load.
# | ||
# This implementation just process nested templates but not resource | ||
# registries. | ||
class RecursiveHotFileLoader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class has too many lines. [140/100]
# eg. URI("file:///a.out").to_s != file:///a.out" | ||
module URI | ||
class FILE < Generic | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra empty line detected at class body beginning.
else | ||
# Deprecated, update_stack(stack_id, stack_name, options = {}) | ||
Fog::Logger.deprecation("#update_stack(stack_id, stack_name, options) is deprecated, use #update_stack(stack, options) instead [light_black](#{caller.first})[/]") | ||
stack_id = arg1 | ||
stack_name = arg2 | ||
params = { | ||
options = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless assignment to variable - options.
|
||
# Ruby URI is not round-trip safe when schema == file | ||
# eg. URI("file:///a.out").to_s != file:///a.out" | ||
module URI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bzwei I need to extend the URI module to fix round-trip safety. Is that fine? Should I put that class elsewhere?
return nil, template | ||
end | ||
|
||
def get_file_contents(from_data, base_url = nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for get_file_contents is too high. [31.29/15]
Cyclomatic complexity for get_file_contents is too high. [14/6]
Method has too many lines. [34/25]
Perceived complexity for get_file_contents is too high. [15/7]
# | ||
# This implementation just process nested templates but not resource | ||
# registries. | ||
class RecursiveHotFileLoader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class has too many lines. [138/100]
else | ||
# Deprecated, update_stack(stack_id, stack_name, options = {}) | ||
Fog::Logger.deprecation("#update_stack(stack_id, stack_name, options) is deprecated, use #update_stack(stack, options) instead [light_black](#{caller.first})[/]") | ||
stack_id = arg1 | ||
stack_name = arg2 | ||
params = { | ||
options = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless assignment to variable - options.
@@ -44,13 +60,13 @@ def update_stack(arg1, arg2 = nil, arg3 = nil) | |||
stack = arg1 | |||
stack_name = stack.stack_name | |||
stack_id = stack.id | |||
params = arg2.nil? ? {} : arg2 | |||
options = arg2.nil? ? {} : arg2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless assignment to variable - options.
# and replaces it with :template. | ||
# see https://github.com/openstack-infra/shade/blob/master/shade/openstackcloud.py#L1201 | ||
# see https://developer.openstack.org/api-ref/orchestration/v1/index.html#create-stack | ||
file_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [124/120]
end | ||
|
||
if options.key?(:template) || options.key?(:template_url) | ||
file_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [126/120]
# and replaces it with :template. | ||
# see https://github.com/openstack-infra/shade/blob/master/shade/openstackcloud.py#L1201 | ||
# see https://developer.openstack.org/api-ref/orchestration/v1/index.html#create-stack | ||
file_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [124/120]
@@ -1,3 +1,5 @@ | |||
require "fog/orchestration/util/recursive_hot_file_loader" # FIXME is there a better way to require this file? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary spacing detected.
Annotation keywords like FIXME should be all upper case, followed by a colon, and a space, then a note describing the problem.
return nil, template | ||
end | ||
|
||
def get_file_contents(from_data, base_url = nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for get_file_contents is too high. [31.29/15]
Cyclomatic complexity for get_file_contents is too high. [14/6]
Method has too many lines. [34/25]
Perceived complexity for get_file_contents is too high. [15/7]
# | ||
# This implementation just process nested templates but not resource | ||
# registries. | ||
class RecursiveHotFileLoader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class has too many lines. [138/100]
else | ||
# Deprecated, update_stack(stack_id, stack_name, options = {}) | ||
Fog::Logger.deprecation("#update_stack(stack_id, stack_name, options) is deprecated, use #update_stack(stack, options) instead [light_black](#{caller.first})[/]") | ||
stack_id = arg1 | ||
stack_name = arg2 | ||
params = { | ||
options = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless assignment to variable - options.
@@ -44,13 +60,13 @@ def update_stack(arg1, arg2 = nil, arg3 = nil) | |||
stack = arg1 | |||
stack_name = stack.stack_name | |||
stack_id = stack.id | |||
params = arg2.nil? ? {} : arg2 | |||
options = arg2.nil? ? {} : arg2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless assignment to variable - options.
# and replaces it with :template. | ||
# see https://github.com/openstack-infra/shade/blob/master/shade/openstackcloud.py#L1201 | ||
# see https://developer.openstack.org/api-ref/orchestration/v1/index.html#create-stack | ||
file_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [124/120]
end | ||
|
||
if options.key?(:template) || options.key?(:template_url) | ||
file_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [126/120]
# and replaces it with :template. | ||
# see https://github.com/openstack-infra/shade/blob/master/shade/openstackcloud.py#L1201 | ||
# see https://developer.openstack.org/api-ref/orchestration/v1/index.html#create-stack | ||
file_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [124/120]
@@ -1,3 +1,5 @@ | |||
require "fog/orchestration/util/recursive_hot_file_loader" # FIXME is there a better way to require this file? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary spacing detected.
Annotation keywords like FIXME should be all upper case, followed by a colon, and a space, then a note describing the problem.
it "#template_file_is_file" do | ||
assert(@file_resolver.template_is_url?("local.yaml")) | ||
refute(@file_resolver.template_is_url?(YAML.dump(@template_yaml))) | ||
refute(@file_resolver.template_is_url?({"a"=>"dict"})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant curly braces around a hash parameter.
Dir.chdir(@oldcwd) | ||
end | ||
|
||
describe "success" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [85/25]
require "open-uri" | ||
require "fog/orchestration/util/recursive_hot_file_loader" # FIXME: is there a better way to require this file? | ||
|
||
describe "Fog::Orchestration[:openstack] | stack requests" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [105/25]
|
||
local_base_url = base_url_for_url(normalise_file_path_to_url(Dir.pwd + "/TEMPLATE")) | ||
|
||
if !(template_file.kind_of?(String) || template_file.kind_of?(Hash)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Favor unless over if for negative conditions.
content | ||
end | ||
|
||
def get_template_contents(template_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for get_template_contents is too high. [22.91/15]
|
||
def template_is_url?(path) | ||
# return true if it's an URI, false otherwise. | ||
begin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant begin block detected.
# | ||
# This implementation just process nested templates but not resource | ||
# registries. | ||
class RecursiveHotFileLoader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class has too many lines. [146/100]
else | ||
# Deprecated, update_stack(stack_id, stack_name, options = {}) | ||
Fog::Logger.deprecation("#update_stack(stack_id, stack_name, options) is deprecated, use #update_stack(stack, options) instead [light_black](#{caller.first})[/]") | ||
stack_id = arg1 | ||
stack_name = arg2 | ||
params = { | ||
options = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless assignment to variable - options.
@@ -44,13 +60,13 @@ def update_stack(arg1, arg2 = nil, arg3 = nil) | |||
stack = arg1 | |||
stack_name = stack.stack_name | |||
stack_id = stack.id | |||
params = arg2.nil? ? {} : arg2 | |||
options = arg2.nil? ? {} : arg2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless assignment to variable - options.
it "#get_file_contents_http_template" do | ||
skip if Fog.mocking? | ||
test_cases = @data["get_file_contents_http_template"].map do |testcase| | ||
[ testcase['input'], testcase['expected'] ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space inside square brackets detected.
# values are absolute paths uri and should be resolved with the local | ||
# directory. | ||
test_cases = @data['get_file_contents_local_template'].map do |testcase| | ||
[ testcase['input'], testcase['expected'] ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space inside square brackets detected.
end | ||
|
||
describe "success" do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra empty line detected at block body beginning.
Dir.chdir(@oldcwd) | ||
end | ||
|
||
describe "success" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [58/25]
require "open-uri" | ||
require "fog/orchestration/util/recursive_hot_file_loader" # FIXME: is there a better way to require this file? | ||
|
||
describe "Fog::Orchestration[:openstack] | stack requests" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [78/25]
return nil, template | ||
end | ||
|
||
def get_file_contents(from_data, base_url = nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for get_file_contents is too high. [27.89/15]
Cyclomatic complexity for get_file_contents is too high. [12/6]
Perceived complexity for get_file_contents is too high. [12/7]
content | ||
end | ||
|
||
def get_template_contents(template_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for get_template_contents is too high. [22.05/15]
# | ||
# This implementation just process nested templates but not resource | ||
# registries. | ||
class RecursiveHotFileLoader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class has too many lines. [141/100]
else | ||
# Deprecated, update_stack(stack_id, stack_name, options = {}) | ||
Fog::Logger.deprecation("#update_stack(stack_id, stack_name, options) is deprecated, use #update_stack(stack, options) instead [light_black](#{caller.first})[/]") | ||
stack_id = arg1 | ||
stack_name = arg2 | ||
params = { | ||
options = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless assignment to variable - options.
@@ -44,13 +60,13 @@ def update_stack(arg1, arg2 = nil, arg3 = nil) | |||
stack = arg1 | |||
stack_name = stack.stack_name | |||
stack_id = stack.id | |||
params = arg2.nil? ? {} : arg2 | |||
options = arg2.nil? ? {} : arg2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless assignment to variable - options.
0c58eea
to
da19385
Compare
Dir.chdir(@oldcwd) | ||
end | ||
|
||
describe "success" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [56/25]
require "open-uri" | ||
require "fog/orchestration/util/recursive_hot_file_loader" # FIXME: is there a better way to require this file? | ||
|
||
describe "Fog::Orchestration[:openstack] | stack requests" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [76/25]
Dir.chdir(@oldcwd) | ||
end | ||
|
||
describe "success" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [35/25]
require "open-uri" | ||
require "fog/orchestration/util/recursive_hot_file_loader" # FIXME: is there a better way to require this file? | ||
|
||
describe "Fog::Orchestration[:openstack] | stack requests" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [55/25]
it "#get_file_contents_simple" do | ||
test_cases = [ | ||
["a string", {}], | ||
[["a", "list"], {}], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use %w or %W for an array of words.
expected = prefix_with_url(["local.yaml", "hot_1.yaml", "file.txt"], @base_url) | ||
args = { | ||
:stack_name => "teststack_files", | ||
:template => YAML.load(open("local.yaml")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer using YAML.safe_load over YAML.load.
content | ||
end | ||
|
||
def get_template_contents(template_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for get_template_contents is too high. [22.05/15]
# | ||
# This implementation just process nested templates but not resource | ||
# registries. | ||
class RecursiveHotFileLoader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class has too many lines. [134/100]
end | ||
|
||
if options.key?(:template) || options.key?(:template_url) | ||
file_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url], options[:files]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [143/120]
# and replaces it with :template. | ||
# see https://github.com/openstack-infra/shade/blob/master/shade/openstackcloud.py#L1201 | ||
# see https://developer.openstack.org/api-ref/orchestration/v1/index.html#create-stack | ||
file_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url], options[:files]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [141/120]
end | ||
|
||
if options.key?(:template) || options.key?(:template_url) | ||
file_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url], options[:files]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [143/120]
# and replaces it with :template. | ||
# see https://github.com/openstack-infra/shade/blob/master/shade/openstackcloud.py#L1201 | ||
# see https://developer.openstack.org/api-ref/orchestration/v1/index.html#create-stack | ||
file_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url], options[:files]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [141/120]
@bzwei Here is the functional test. There's a commented script on how to run this. |
# throw exceptions enables stack creation to fail | ||
# with a suitable error. | ||
# | ||
# XXX Implement a retry here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This first implementation won't contain a retry. It could be added in the future.
end # Class | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Final newline missing.
|
||
YAML.safe_load(YAML.dump(item), [Date]) | ||
end | ||
end # Class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not place comments on the same line as the end keyword.
# replaced with their absolute URI as done in heatclient | ||
# and shade. | ||
# | ||
def get_file_contents(from_data, base_url = nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for get_file_contents is too high. [20.9/15]
Cyclomatic complexity for get_file_contents is too high. [9/6]
Perceived complexity for get_file_contents is too high. [9/7]
# | ||
# This implementation just process nested templates but not resource | ||
# registries. | ||
class RecursiveHotFileLoader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class has too many lines. [119/100]
# and replaces it with :template. | ||
# see https://github.com/openstack-infra/shade/blob/master/shade/openstackcloud.py#L1201 | ||
# see https://developer.openstack.org/api-ref/orchestration/v1/index.html#create-stack | ||
file_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url], options[:files]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better this way
if options[:files].nil?
file_resolver = Fog::Orchestration::Util::RecursiveFileLoader.new(options[:template] || options[:template_url])
files = file_resolver.get_files
options[:files] = files unless files.empty?
options[:template] = file_resolver.template
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:files reintroduced after gitter discussion
class RecursiveHotFileLoader | ||
attr_reader :files | ||
attr_reader :template | ||
attr_reader :visited |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete, no need to expose it as read_only attribute
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
visited
removedtemplate
is used to return the processed template with URIs
attr_reader :template | ||
attr_reader :visited | ||
|
||
def initialize(template, files = nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def initialize(template)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reintroduced after gitter discussion
# Serialize the template hash to deep-copy it and | ||
# avoid modifying the argument. Instead create a | ||
# new one to be modified by get_file_contents. | ||
@template = deep_copy(template) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to deep_copy. Why do we expect template can be a Hash? Initially it is either the content string or url.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://github.com/fog/fog-openstack/blob/master/docs/orchestration.md#stacks
stack_update accepts Hash too.
https://github.com/fog/fog-openstack/blame/master/docs/orchestration.md#L122
# from the above link.
heat_template = { "template": { "description": "Updated description" } }
stack.save(heat_template)
This allows the code to work in both cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, we agreed on irc to leave the deepcopy and support Hash to support orchestration.md examples.
end | ||
|
||
def get_files | ||
return @files unless @files.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return @files unless @files.nil? # avoid processing templates for every `get_files` call
@files = {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bzwei agreed on gitter that we'll reintroduce files
argument.
# avoid modifying the argument. Instead create a | ||
# new one to be modified by get_file_contents. | ||
@template = deep_copy(template) | ||
@files = files || {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bzwei reintroduced after gitter discussion.
@visited = Set.new | ||
end | ||
|
||
def get_files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_files
method is not needed if we write initialize
this way
def initialize(template)
@files = {}
@visited = Set.new
@template = get_template_content(template)
end
In the caller you can simply
file_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url]
options[:template] = file_resolver.template
options[:files] = file_resolver.files unless file_resolver.files.empty?
end.compact | ||
test_cases.each do |data, _| | ||
assert_raises ArgumentError, URI::InvalidURIError do | ||
file_resolver = Fog::Orchestration::Util::RecursiveHotFileLoader.new(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless assignment to variable - file_resolver.
Dir.chdir(@oldcwd) | ||
end | ||
|
||
describe "success" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [69/25]
require "open-uri" | ||
require "fog/orchestration/util/recursive_hot_file_loader" | ||
|
||
describe "Fog::Orchestration[:openstack] | stack requests" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [89/25]
# | ||
# XXX: we could use named parameters | ||
# and better mimic heatclient implementation. | ||
def get_template_contents(template_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for get_template_contents is too high. [23.39/15]
# | ||
# This implementation just process nested templates but not resource | ||
# registries. | ||
class RecursiveHotFileLoader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class has too many lines. [114/100]
dc500f8
to
908fe22
Compare
# | ||
# This implementation just process nested templates but not resource | ||
# registries. | ||
class RecursiveHotFileLoader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class has too many lines. [112/100]
# replaced with their absolute URI as done in heatclient | ||
# and shade. | ||
# | ||
def get_file_contents(from_data, base_url = nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can base_url
ever be nil
? You always have a base_url when calling from get_template_contents
. We don't need a default value here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
Fog::Logger.debug("Processing #{from_data} with base_url #{base_url}") | ||
|
||
# Recursively traverse the tree. | ||
if recurse_if(from_data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need a recuse_if
method because you need to test again whether from_data
is a Hash
.
Consider
recurse_data = from_data.kind_of?(Hash) ? from_data.values : from_data
recurse_data.each { |value| get_file_contents(value, base_url) } if recurse_data.kind_of?(Array)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is more flexible/readable having a single function to decide, but your implementation is so clever :D
I changed it and added a small comment to make it more straightforward.
raise ArgumentError if url.host.nil? && remote_schemes.include?(url.scheme) | ||
|
||
# Encode URI with spaces. | ||
uri_or_filename = URI.encode(URI.decode(URI(uri_or_filename).to_s)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to address the obsolete warning?
you already have url
, so the line could be url_or_filename = URI.encode(URI.decode(url.to_s))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1- I'm finding a suitable replacement for URI.decode. Hints welcome.
2- Applied your suggestion and removed the 3rd URI
call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced with gsub(/ /, "%20")
end | ||
|
||
def deep_copy(item) | ||
return item if item.kind_of?(String) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better
return item unless item.kind_of?(Hash)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while imho:
- that won't deep_copy arrays
- may result counter-intuitive during further development
I'm fine for changing if it's a merge-blocker ;)
# replaced with their absolute URI as done in heatclient | ||
# and shade. | ||
# | ||
def get_file_contents(from_data, base_url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for get_file_contents is too high. [20.9/15]
Cyclomatic complexity for get_file_contents is too high. [9/6]
Perceived complexity for get_file_contents is too high. [9/7]
# | ||
# This implementation just process nested templates but not resource | ||
# registries. | ||
class RecursiveHotFileLoader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class has too many lines. [107/100]
@@ -1,3 +1,5 @@ | |||
require "fog/orchestration/util/recursive_hot_file_loader" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add the package in https://github.com/fog/fog-openstack/blob/master/lib/fog/openstack.rb then you don't need to require
here and nor need to use the full namespace while using the resolver class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rock! Thank you!!!
require "yaml" | ||
require "open-uri" | ||
|
||
describe "Fog::Orchestration[:openstack] | stack requests" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [89/25]
require "yaml" | ||
require "open-uri" | ||
|
||
describe "Fog::Orchestration[:openstack] | stack requests" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block has too many lines. [65/25]
end | ||
|
||
if options.key?(:template) || options.key?(:template_url) | ||
file_resolver = Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url], options[:files]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [123/120]
# and replaces it with :template. | ||
# see https://github.com/openstack-infra/shade/blob/master/shade/openstackcloud.py#L1201 | ||
# see https://developer.openstack.org/api-ref/orchestration/v1/index.html#create-stack | ||
file_resolver = Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url], options[:files]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [121/120]
end | ||
|
||
if options.key?(:template) || options.key?(:template_url) | ||
file_resolver = Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url], options[:files]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [123/120]
# and replaces it with :template. | ||
# see https://github.com/openstack-infra/shade/blob/master/shade/openstackcloud.py#L1201 | ||
# see https://developer.openstack.org/api-ref/orchestration/v1/index.html#create-stack | ||
file_resolver = Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url], options[:files]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [121/120]
@ioggstream Thanks! |
@bzwei Thanks to you! |
The implementation is based on the python-heatclient one. Where needed, test data is retrieved from a yaml file. This code allows creating a first simple stack referencing get_file: resources.
Ruby URI module uses minimal file representation (eg. file:/etc/hosts) instead of the traditional one (eg. file:///etc/hosts). Created functions to mimic Heat URI behavior (file:///).
* added Heat spec references in comments; * removed redundant traversal; * moved log.warnings to log.debug in template traversal; * removed 1.9 support code;
* Simplified local path normalization. * Rename get_content to read_uri
When a Hash template is passed, it shouldn't be modified in-place. When a files parameter is passed, the files referenced by existing keys should be skipped, the missing ones should be added in-place. This enables overriding discovered files location.
…ecated URI methods. Files are now resolved - downloaded and parsed - at instance initialization. It is not necessary to call the resolver method anymore. This enabled removing some methods. This commit removes the deprecaded URI.encode and URI.decode methods.
b1393ad
to
ef26536
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @bzwei for a detail review. I've browsed this couple of times and it looks acceptable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @bzwei for a detail review. I've browsed this couple of times and it looks acceptable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @bzwei for a detail review. I've browsed this couple of times and it looks acceptable.
eh, github acts funky |
What does it do?
Resolve files in yaml template.
get_file specs are here https://docs.openstack.org/heat/pike/template_guide/hot_spec.html#get-file