-
Notifications
You must be signed in to change notification settings - Fork 12
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
Migration tests for KVM/Xen #79
base: master
Are you sure you want to change the base?
Changes from all commits
03969eb
559a970
bf00381
5f23774
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,3 @@ Feature: Controller node | |
|
||
@system | ||
Scenario: Essential system requirements | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
@migration | ||
Feature: Instance migration | ||
As administrator | ||
I want to make sure that Instance migration is working correctly | ||
|
||
Background: | ||
Given At least 2 Compute nodes must be enabled | ||
And Image is available | ||
|
||
@kvm | ||
Scenario: Test KVM migration | ||
Given At least 2 KVM Hypervisors are available | ||
When I create an KVM instance | ||
And Instance is running | ||
And I migrate KVM instance | ||
Then I expect the instance will run on different host | ||
And will be in state "ACTIVE" | ||
And I turn off the instance(so it will not use resources) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parenthesis should be avoided in feature files, usually it works by adding short sentence e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
|
||
@xen | ||
Scenario: Test Xen migrationnd I turn off the instance(so it will not use resources) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All following after word migration doesn't seem to belong there There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
Given At least 2 Xen Hypervisors are available | ||
When I create an Xen instance | ||
And Instance is running | ||
And I migrate Xen instance | ||
Then I expect the instance will run on different host | ||
And will be in state "ACTIVE" | ||
And I turn off the instance(so it will not use resources) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parenthesis There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Given(/^At least (\d+) Compute nodes must be enabled$/) do |arg1| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usually you want to give some real name to parameters in blocks to recognize later what kind of object you are expecting, in this case it would be e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
# get hypervisors and count Xen's ones - for migration we need 2 | ||
enabled_host_list = control_node.exec!("openstack host list -f value --zone nova").output | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could handle the output directly here by |
||
expect(enabled_host_list.each_line(separator=$/).to_a.count).to be >= arg1.to_i | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... and bring the variable in it's final form into the expectation line. |
||
end | ||
|
||
Given(/^Image is available$/) do | ||
# check image | ||
image_name = "jeos" | ||
images = control_node.openstack.image.list | ||
images.each do |i| | ||
@image_id = i.id if i.name == image_name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The image = images.find {|img| img.name == image_name} And to test existence of the image, you don't need id value here or later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
end | ||
expect(@image_id).not_to be_empty | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
Given(/^At least (\d+) Xen Hypervisors are available$/) do |arg1| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use of default param name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
# get hypervisors and count Xen's ones - for migration at least 2 | ||
hashypervisor_xen = 0 | ||
@hypervisors = control_node.openstack.hypervisor.list | ||
expect(@hypervisors).not_to be_empty | ||
|
||
@hypervisors.each do |h| | ||
hypervisor = control_node.openstack.hypervisor.show(h.id) | ||
hashypervisor_xen = (hashypervisor_xen + 1) if hypervisor.hypervisor_type == "Xen" | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Ruby you have nice methods for handling collections, you could use xen_nodes = @hypervisors.select do |hv|
control_node.openstack.hypervisor.show(hv.id).hypervisor_type == "Xen"
end
expect(xen_node.size).to be >= arg1.to_i There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cool...ok |
||
expect(hashypervisor_xen).to be >= arg1.to_i | ||
end | ||
|
||
Given(/^At least (\d+) KVM Hypervisors are available$/) do |arg1| | ||
# get hypervisors and count KVM's ones - for migration at least 2 | ||
hashypervisor_kvm = 0 | ||
@hypervisors = control_node.openstack.hypervisor.list | ||
expect(@hypervisors).not_to be_empty | ||
|
||
@hypervisors.each do |h| | ||
hypervisor = control_node.openstack.hypervisor.show(h.id) | ||
hashypervisor_kvm = (hashypervisor_kvm + 1) if hypervisor.hypervisor_type == "QEMU" | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar as for Xen nodes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
expect(hashypervisor_kvm).to be >= arg1.to_i | ||
end | ||
|
||
When(/^I create an KVM instance$/) do | ||
def delete_old_instances(server_id) | ||
puts("old instance #{server_id } found - deleting") | ||
control_node.exec!("openstack server delete #{server_id}") | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be better to move this method into step helpers https://github.com/SUSE-Cloud/cct/blob/master/features/support/step_helpers.rb , then you don't need to define it again in the context of the next step. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, makes sense... ok |
||
## TODO add --key-name zkubala | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
# clean old instances | ||
@servers = control_node.openstack.server.list | ||
@instance_name = "kvm_mig_instance" | ||
@servers.each do |s| | ||
s.name == @instance_name and delete_old_instances(s.id) | ||
end | ||
# create a new instance | ||
new_instance = control_node.exec!("openstack server create -f shell --flavor m1.smaller --image jeos --security-group default -c id #{@instance_name}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is a bit too long, splitting it into several lines usually works: command = "openstack server create -f shell --flavor m1.smaller --image jeos " +
"--security-group default -c id #{@instance_name}" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
@new_instance_id = new_instance.output[4, 36] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed? The output only should contain the server id (looking at -c id from the command above). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it shows There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the end |
||
puts ("New instance id: #{@new_instance_id}") | ||
end | ||
|
||
When(/^I create an Xen instance$/) do | ||
def delete_old_instances(server_id) | ||
puts("old instance #{server_id } found - deleting") | ||
control_node.exec!("openstack server delete #{server_id}") | ||
end | ||
## TODO add --key-name zkubala | ||
# clean old instances | ||
@servers = control_node.openstack.server.list | ||
@instance_name = "xen_mig_instance" | ||
@servers.each do |s| | ||
s.name == @instance_name and delete_old_instances(s.id) | ||
end | ||
# create a new instance | ||
new_instance = control_node.exec!("openstack server create -f shell --flavor m1.smaller --image jeos --security-group default -c id #{@instance_name}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also a line too long. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
@new_instance_id = new_instance.output[4, 36] | ||
puts ("New instance id: #{@new_instance_id}") | ||
end | ||
|
||
When(/^Instance is running$/) do | ||
## TODO Raise an expection if in ERROR state | ||
# it may take some time before the instance turns active | ||
wait_for "Checking that instance status is active", max: "120 seconds", sleep: "4 seconds" do | ||
@instance_show = control_node.openstack.server.show(@new_instance_id) | ||
break if @instance_show.status == "ACTIVE" | ||
end | ||
end | ||
|
||
When(/^I migrate Xen instance$/) do | ||
# get actual host of the instance and migrate it | ||
@instance_host = @instance_show.send("os-ext-srv-attr:host") | ||
puts "Instance running on: #{@instance_host}" | ||
instance_migrate = control_node.exec!("openstack server migrate --shared-migration #{@new_instance_id}") | ||
|
||
# it may take some time before the instance turns verify_resize | ||
wait_for "Checking that instance status is verify_resize", max: "300 seconds", sleep: "10 seconds" do | ||
instance_show = control_node.openstack.server.show(@new_instance_id) | ||
if instance_show.status == "VERIFY_RESIZE" | ||
puts "Migration finished, confirming..." | ||
control_node.exec!("openstack server resize --confirm #{@new_instance_id}") | ||
break | ||
end | ||
end | ||
end | ||
|
||
When(/^I migrate KVM instance$/) do | ||
# get actual host of the instance and migrate it | ||
@instance_host = @instance_show.send("os-ext-srv-attr:host") | ||
puts "Instance running on: #{@instance_host}" | ||
instance_migrate = control_node.exec!("openstack server migrate #{@new_instance_id}") | ||
|
||
# it may take some time before the instance turns verify_resize | ||
wait_for "Checking that instance status is verify_resize", max: "300 seconds", sleep: "10 seconds" do | ||
instance_show = control_node.openstack.server.show(@new_instance_id) | ||
if instance_show.status == "VERIFY_RESIZE" | ||
puts "Migration finished, confirming..." | ||
control_node.exec!("openstack server resize --confirm #{@new_instance_id}") | ||
break | ||
end | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This step has exact same implementation as the one for Xen, it should work for both to parametrize the hypervisor name in the step line in the feature file, e.g. |
||
|
||
Then(/^I expect the instance will run on different host$/) do | ||
instance_show = control_node.openstack.server.show(@new_instance_id) | ||
instance_host = instance_show.send("os-ext-srv-attr:host") | ||
puts "Instance running on: #{instance_host}" | ||
expect(@instance_host).not_to eq(instance_host) | ||
|
||
end | ||
|
||
Then(/^will be in state "([^"]*)"$/) do |arg1| | ||
wait_for "Checking that instance status is ACTIVE", max: "40 seconds", sleep: "10 seconds" do | ||
instance_show = control_node.openstack.server.show(@new_instance_id) | ||
break if instance_show.status == "ACTIVE" | ||
end | ||
end | ||
|
||
Then(/^I turn off the instance\(so it will not use resources\)$/) do | ||
control_node.exec!("openstack server stop #{@new_instance_id}") | ||
wait_for "Checking that instance status is SHUTOFF", max: "120 seconds", sleep: "10 seconds" do | ||
instance_show = control_node.openstack.server.show(@new_instance_id) | ||
break if instance_show.status == "SHUTOFF" | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Cct | ||
module Commands | ||
module Openstack | ||
class Hypervisor < Command | ||
self.command = ["hypervisor"] | ||
def list *options | ||
super(*(options << {row: Struct.new(:id, :"Hypervisor Hostname")})) | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Cct | ||
module Commands | ||
module Openstack | ||
class Server < Command | ||
self.command = ["server"] | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace :feature do | ||
feature_name "Instance migration" | ||
|
||
namespace :migration do | ||
desc "Test KVM migration" | ||
feature_task :kvm, tags: :@kvm | ||
|
||
desc "Test Xen migration" | ||
feature_task :xen, tags: :@xen | ||
end | ||
|
||
desc "Complete verification of 'Instance migration' feature" | ||
task :migration => "migration:kvm" | ||
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.
Let's make it more explicit we expect having 2 nodes, e.g.
At least 2 nodes with KVM hypervisors
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