Skip to content
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

Refactoring the cloud orchestration check_provisioned method #12712

Merged
merged 2 commits into from
Dec 2, 2016
Merged

Refactoring the cloud orchestration check_provisioned method #12712

merged 2 commits into from
Dec 2, 2016

Conversation

pkomanek
Copy link
Contributor

Purpose or Intent

Refactoring the check_provisioned method for the miq_ae_orchestration based on the issue below.

Links [Optional]

#12038

@pkomanek
Copy link
Contributor Author

@miq-bot add_labels automate, enhancement, refactoring, wip

@gmcculloug
Copy link
Member

cc @bzwei

@pkomanek
Copy link
Contributor Author

@miq-bot remove_label wip

@pkomanek pkomanek changed the title [WIP]Refactoring the cloud orchestration check_provisioned method Refactoring the cloud orchestration check_provisioned method Nov 23, 2016
@miq-bot miq-bot removed the wip label Nov 23, 2016
true
end

def state_and_root_vars(service)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method name is not meaningful. The main logic in this method to prepare and call provider refresh.

provider = service.orchestration_manager
def main
task = @handle.root["service_template_provision_task"]
service = task.try(:destination)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to test whether service exists and is a type of ServiceOrchestration. Log and exit if not.

end
end

before(:each) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for (:each), just before { }


it "completes check_provisioned step when refresh is done" do
allow(svc_model_service).to receive(:orchestration_stack).and_return(svc_model_amazon_stack)
allow(ae_service).to receive(:state_var_exist?)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not mock ae_service because this is the class we are testing. Methods such as #state_var_exists?, #refresh_may_have_completed? are internal implementation details that should not be mocked.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkomanek
https://github.com/ManageIQ/manageiq/blob/master/spec/support/miq_ae_mock_service.rb#L15
We can pass in all of these as a hash into the miq_ae_mock_service

expect(ae_service.root['ae_reason']).to eq('Stack was rolled back')
end

it "refreshes the provider and waits for it to complete" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please group all refresh related tests in a context and share the same before block where you can prepare for example to return svc_model_amazon_stack

@miq-bot
Copy link
Member

miq-bot commented Nov 30, 2016

<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush.

@pkomanek pkomanek closed this Nov 30, 2016
@pkomanek pkomanek reopened this Nov 30, 2016
unless service && service.instance_of?(MiqAeMethodService::MiqAeServiceServiceOrchestration)
@handle.log(:error, 'Service does not exist or has a different' \
' type from MiqAeServiceServiceOrchestration')
exit(MIQ_STOP)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkomanek
We can't use an exit in Automate methods because when we are running in test mode, the exit will end rspec.
You can raise an exception if the service is invalid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkanoor
I know about the ending rspec tests after the getting exit, I was trying to find a way how to catch it today and this line of code expect { described_class.new(ae_service).main }.to_not raise_error seems working for me. I can change that from exit to raise an exception if you want. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkomanek yes lets do that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkomanek
Should we check for the service first and then check the type of service.
Otherwise for nil we would be saying it is a different kind of service

@miq-bot
Copy link
Member

miq-bot commented Dec 1, 2016

Checked commits pkomanek/manageiq@73af5ef~...349df1b with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1
2 files checked, 0 offenses detected
Everything looks good. 🏆

@pkomanek
Copy link
Contributor Author

pkomanek commented Dec 1, 2016

@mkanoor
I split the service control check into 2 different checks for Service is nil and Service has a different type from MiqAeServiceServiceOrchestration. I also changed the exit(MIQ_STOP) to raise one of these exceptions and added 2 new tests to spec for checking correct raising of these exceptions.

@mkanoor mkanoor added this to the Sprint 50 Ending Dec 5, 2016 milestone Dec 2, 2016
@mkanoor mkanoor merged commit f0d6f1b into ManageIQ:master Dec 2, 2016
@pkomanek pkomanek deleted the refactoring_cloud_orchestration_check_provisioned_method branch December 5, 2016 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants