From 134cc6f368a7d68e0f8b0bd6bc1f4dbdcbdcd60b Mon Sep 17 00:00:00 2001 From: kaustubh-d Date: Thu, 6 Jun 2013 10:47:34 +0530 Subject: [PATCH] test cases for azure cloud attributes loaded via ohai hints. --- .../list_deployments_for_service004.xml | 116 ++++++++++++++++++ spec/unit/assets/list_hosts.xml | 2 +- spec/unit/azure_server_create_spec.rb | 50 ++++++++ spec/unit/query_azure_mock.rb | 5 + 4 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 spec/unit/assets/list_deployments_for_service004.xml diff --git a/spec/unit/assets/list_deployments_for_service004.xml b/spec/unit/assets/list_deployments_for_service004.xml new file mode 100644 index 0000000..f2c5d92 --- /dev/null +++ b/spec/unit/assets/list_deployments_for_service004.xml @@ -0,0 +1,116 @@ + + + deployment004 + Production + 2b1f2f0a4b414088a0ec64d583d9c4b3 + Running + + http://service004.cloudapp-preview.net/ + PFNlcnZpY2VDb25maWd1cmF0aW9uIHhtbG5zOnhzaT0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEtaW5zdGFuY2UiIHhtbG5zOnhzZD0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEiIHhtbG5zPSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL1NlcnZpY2VIb3N0aW5nLzIwMDgvMTAvU2VydmljZUNvbmZpZ3VyYXRpb24iPg0KICA8Um9sZSBuYW1lPSJyb2xlMDAyIj4NCiAgICA8SW5zdGFuY2VzIGNvdW50PSIxIiAvPg0KICA8L1JvbGU+DQogIDxSb2xlIG5hbWU9InJvbGUwMDEiPg0KICAgIDxJbnN0YW5jZXMgY291bnQ9IjEiIC8+DQogIDwvUm9sZT4NCjwvU2VydmljZUNvbmZpZ3VyYXRpb24+ + + + ssh-vm + ssh-vm + ReadyRole + 0 + 0 + ExtraSmall + + 10.26.198.146 + + + tcpport66 + 65.52.251.57 + 66 + 66 + tcp + + + SSH + 65.52.249.191 + 22 + 22 + tcp + + + Started + ssh-vm + + + winrm-vm + winrm-vm + ReadyRole + 0 + 0 + Small + + 10.26.196.254 + + + winrm + 65.52.249.191 + 5985 + 5985 + tcp + + + Started + winrm-vm + + + 1 + + + ssh-vm + WA-GUEST-OS-1.18_201203-01 + + + NetworkConfiguration + + + 60657 + tcp + 65.52.249.191 + + + + + + + + winrm-vm + WA-GUEST-OS-1.18_201203-01 + PersistentVMRole + + + NetworkConfiguration + + + 5985 + winrm + 5985 + tcp + 65.52.249.191 + + + + + + + + ReadWrite + deployment004-winrm-vm-0-201241722113 + http://auxpreview104imagestore.blob.core.azure-preview.com/os-disks/disk001 + SUSE__OpenSUSE64121-03192012-en-us-15GB + Linux + + Small + + + 1.7 + false + true + 2012-04-17T22:01:10Z + 2012-04-23T23:52:09Z + + diff --git a/spec/unit/assets/list_hosts.xml b/spec/unit/assets/list_hosts.xml index aba29a1..8c8c237 100755 --- a/spec/unit/assets/list_hosts.xml +++ b/spec/unit/assets/list_hosts.xml @@ -1 +1 @@ -https://management-preview.core.windows-int.net/155a9851-88a8-49b4-98e4-58055f08f412/services/hostedservices/service001service001Explicitly created hosted serviceWindows Azure PreviewCreated2012-04-17T21:56:23Z2012-04-17T22:01:08Zhttps://management-preview.core.windows-int.net/155a9851-88a8-49b4-98e4-58055f08f412/services/hostedservices/service002service002Explicitly created hosted serviceWindows Azure PreviewCreated2012-04-17T22:27:08Z2012-04-23T21:42:47Zhttps://management-preview.core.windows-int.net/155a9851-88a8-49b4-98e4-58055f08f412/services/hostedservices/service003service003Explicitly created hosted serviceWindows Azure PreviewCreated2012-04-19T20:17:26Z2012-04-19T20:17:25Z +https://management-preview.core.windows-int.net/155a9851-88a8-49b4-98e4-58055f08f412/services/hostedservices/service001service001Explicitly created hosted serviceWindows Azure PreviewCreated2012-04-17T21:56:23Z2012-04-17T22:01:08Zhttps://management-preview.core.windows-int.net/155a9851-88a8-49b4-98e4-58055f08f412/services/hostedservices/service002service002Explicitly created hosted serviceWindows Azure PreviewCreated2012-04-17T22:27:08Z2012-04-23T21:42:47Zhttps://management-preview.core.windows-int.net/155a9851-88a8-49b4-98e4-58055f08f412/services/hostedservices/service003service003Explicitly created hosted serviceWindows Azure PreviewCreated2012-04-19T20:17:26Z2012-04-19T20:17:25Zhttps://management-preview.core.windows-int.net/155a9851-88a8-49b4-98e4-58055f08f412/services/hostedservices/service004service004Explicitly created hosted serviceWindows Azure PreviewCreated2012-04-17T21:56:23Z2012-04-17T22:01:08Z diff --git a/spec/unit/azure_server_create_spec.rb b/spec/unit/azure_server_create_spec.rb index 5f60da6..3d9d1b9 100644 --- a/spec/unit/azure_server_create_spec.rb +++ b/spec/unit/azure_server_create_spec.rb @@ -130,6 +130,56 @@ describe "parameter test:" do end end +describe "cloud attributes" do + context "WinRM protocol:" do + before do + @bootstrap = Chef::Knife::BootstrapWindowsWinrm.new + Chef::Knife::BootstrapWindowsWinrm.stub(:new).and_return(@bootstrap) + @bootstrap.should_receive(:run) + @server_instance.should_receive(:is_image_windows?).any_number_of_times.and_return(true) + Chef::Config[:knife][:bootstrap_protocol] = 'winrm' + Chef::Config[:knife][:winrm_password] = 'winrm_password' + Chef::Config[:knife][:azure_dns_name] = 'service004' + Chef::Config[:knife][:azure_vm_name] = 'winrm-vm' + Chef::Config[:knife][:hints] = nil # reset as this is loaded only once for app(test here) + @server_instance.run + end + + it "should set the cloud attributes in hints" do + cloud_attributes = Chef::Config[:knife][:hints]["azure"] + cloud_attributes["public_ip"].should == "65.52.249.191" + cloud_attributes["vm_name"].should == "winrm-vm" + cloud_attributes["public_fqdn"].should == "service004.cloudapp.net" + cloud_attributes["public_ssh_port"].should be_nil + cloud_attributes["public_winrm_port"].should == "5985" + end + end + context "SSH protocol:" do + before do + @bootstrap = Chef::Knife::Bootstrap.new + Chef::Knife::Bootstrap.stub(:new).and_return(@bootstrap) + @bootstrap.should_receive(:run) + @server_instance.should_receive(:is_image_windows?).any_number_of_times.and_return(false) + Chef::Config[:knife][:bootstrap_protocol] = 'ssh' + Chef::Config[:knife][:ssh_password] = 'ssh_password' + Chef::Config[:knife][:ssh_user] = 'ssh_user' + Chef::Config[:knife][:azure_dns_name] = 'service004' + Chef::Config[:knife][:azure_vm_name] = 'ssh-vm' + Chef::Config[:knife][:hints] = nil # reset as this is loaded only once for app(test here) + @server_instance.run + end + + it "should set the cloud attributes in hints" do + cloud_attributes = Chef::Config[:knife][:hints]["azure"] + cloud_attributes["public_ip"].should == "65.52.251.57" + cloud_attributes["vm_name"].should == "ssh-vm" + cloud_attributes["public_fqdn"].should == "service004.cloudapp.net" + cloud_attributes["public_ssh_port"].should == "22" + cloud_attributes["public_winrm_port"].should be_nil + end + end +end + describe "for bootstrap protocol winrm:" do before do Chef::Config[:knife][:bootstrap_protocol] = 'winrm' diff --git a/spec/unit/query_azure_mock.rb b/spec/unit/query_azure_mock.rb index 429803e..2f286df 100755 --- a/spec/unit/query_azure_mock.rb +++ b/spec/unit/query_azure_mock.rb @@ -43,6 +43,8 @@ module QueryAzureMock retval = Nokogiri::XML readFile('list_deployments_for_service002.xml') elsif name == 'hostedservices/service003/deploymentslots/Production' retval = Nokogiri::XML readFile('list_deployments_for_service003.xml') + elsif name == 'hostedservices/service004/deploymentslots/Production' + retval = Nokogiri::XML readFile('list_deployments_for_service004.xml') elsif name == 'storageservices' retval = Nokogiri::XML readFile('list_storageaccounts.xml') else @@ -61,6 +63,9 @@ module QueryAzureMock elsif name == 'hostedservices/service001/deployments/deployment001/roles' retval = Nokogiri::XML readFile('post_success.xml') @receivedXML = body + elsif name == 'hostedservices/service004/deployments/deployment004/roles' + retval = Nokogiri::XML readFile('post_success.xml') + @receivedXML = body elsif name =~ /hostedservices\/vm01.*\/deployments/ retval = Nokogiri::XML readFile('post_success.xml') @receivedXML = body