diff --git a/app/models/manageiq/providers/lenovo/physical_infra_manager/physical_switch.rb b/app/models/manageiq/providers/lenovo/physical_infra_manager/physical_switch.rb index 1775c1cc14..07e6bf5d38 100644 --- a/app/models/manageiq/providers/lenovo/physical_infra_manager/physical_switch.rb +++ b/app/models/manageiq/providers/lenovo/physical_infra_manager/physical_switch.rb @@ -1,4 +1,5 @@ module ManageIQ::Providers class Lenovo::PhysicalInfraManager::PhysicalSwitch < ::PhysicalSwitch + include_concern 'Operations' end end diff --git a/app/models/manageiq/providers/lenovo/physical_infra_manager/physical_switch/operations.rb b/app/models/manageiq/providers/lenovo/physical_infra_manager/physical_switch/operations.rb new file mode 100644 index 0000000000..f0da63e887 --- /dev/null +++ b/app/models/manageiq/providers/lenovo/physical_infra_manager/physical_switch/operations.rb @@ -0,0 +1,27 @@ +module ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalSwitch::Operations + extend ActiveSupport::Concern + + # + # Restarts the physical switch. + # it does the `power_cycle_soft` operation. + # + def restart + change_resource_state(:power_cycle_soft_switch) + end + + private + + # + # Sends the power operation for a Switch. + # + def change_resource_state(verb) + $lenovo_log.info("The :#{verb} for Physical Switch with uuid: #{uid_ems} is in progress") + + ems = ExtManagementSystem.find(ems_id) + response = ems.connect.send(verb, uid_ems) + + $lenovo_log.info("The :#{verb} for Physical Switch with uuid: #{uid_ems} is completed") + + response + end +end diff --git a/spec/factories/physical_switch.rb b/spec/factories/physical_switch.rb new file mode 100644 index 0000000000..073ee3a770 --- /dev/null +++ b/spec/factories/physical_switch.rb @@ -0,0 +1,4 @@ +FactoryGirl.define do + factory :lenovo_physical_switch, :class => ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalSwitch do + end +end diff --git a/spec/models/manageiq/providers/lenovo/physical_infra_manager/physical_switch_spec.rb b/spec/models/manageiq/providers/lenovo/physical_infra_manager/physical_switch_spec.rb new file mode 100644 index 0000000000..2e2f3a4a86 --- /dev/null +++ b/spec/models/manageiq/providers/lenovo/physical_infra_manager/physical_switch_spec.rb @@ -0,0 +1,39 @@ +require "xclarity_client" +require "faker" + +describe ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalSwitch do + context 'power operations' do + let(:physical_switch) do + physical_infra_manager = FactoryGirl.create( + :physical_infra, + :name => "LXCA", + :hostname => "10.243.9.123", + :port => "443", + :ipaddress => "https://10.243.9.123" + ) + + auth = FactoryGirl.create( + :authentication, + :userid => "admin", + :password => "password", + :authtype => "default" + ) + + physical_infra_manager.authentications = [auth] + + FactoryGirl.create( + :lenovo_physical_switch, + :name => "Physical_Switch", + :uid_ems => "27997dba5dba11e89c2dfa7ae01bbebc", + :ext_management_system => physical_infra_manager + ) + end + + it 'should restart the physical switch' do + VCR.use_cassette("#{described_class.name.underscore}_restart") do + response = physical_switch.restart + expect(response.status).to eq(200) + end + end + end +end diff --git a/spec/vcr_cassettes/manageiq/providers/lenovo/physical_infra_manager/physical_switch_restart.yml b/spec/vcr_cassettes/manageiq/providers/lenovo/physical_infra_manager/physical_switch_restart.yml new file mode 100644 index 0000000000..7486e36b91 --- /dev/null +++ b/spec/vcr_cassettes/manageiq/providers/lenovo/physical_infra_manager/physical_switch_restart.yml @@ -0,0 +1,65 @@ +--- +http_interactions: +- request: + method: put + uri: https://10.243.9.123/switches/27997dba5dba11e89c2dfa7ae01bbebc + body: + encoding: UTF-8 + string: '{"powerState":"powerCycleSoft"}' + headers: + User-Agent: + - LXCA via Ruby Client/0.5.8 (ManageIQ/master) + Authorization: + - Basic Y2hnX3Bhc3M6dmFsaWRAMTIz + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Date: + - Tue, 22 May 2018 18:07:50 GMT + Set-Cookie: + - userAuthenticationMethod=local;Path=/;Secure + Expires: + - "-1" + - Thu, 01 Jan 1970 00:00:00 GMT + Strict-Transport-Security: + - max-age=15550200; includeSubDomains; + X-Frame-Options: + - SAMEORIGIN + X-Content-Type-Options: + - nosniff + X-Xss-Protection: + - 1; mode=block + Content-Security-Policy: + - default-src 'self' ; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src + 'self' 'unsafe-inline'; worker-src 'self' blob:; child-src 'self' blob:; img-src + 'self' data:; + Cache-Control: + - no-store, no-cache, must-revalidate + Pragma: + - no-cache + Content-Type: + - application/com.lenovo.lxca-v2.0.0+json; charset=UTF-8 + Content-Language: + - en-US + Location: + - "/jobs/2893" + Jobids: + - '2893' + Vary: + - Accept-Encoding, User-Agent + Transfer-Encoding: + - chunked + body: + encoding: ASCII-8BIT + string: "{}" + http_version: + recorded_at: Tue, 22 May 2018 18:07:26 GMT +recorded_with: VCR 3.0.3