From f64c8010369f2a2d37d3eb1006ccab25bbc25524 Mon Sep 17 00:00:00 2001 From: Eric Bischoff Date: Tue, 29 Aug 2023 15:43:51 +0200 Subject: [PATCH] Fix hostname rename feature --- .../secondary/srv_rename_hostname.feature | 27 +++++++++++++------ .../step_definitions/command_steps.rb | 22 ++++++++------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/testsuite/features/secondary/srv_rename_hostname.feature b/testsuite/features/secondary/srv_rename_hostname.feature index 76fdbcb837b4..05e65bef3b73 100644 --- a/testsuite/features/secondary/srv_rename_hostname.feature +++ b/testsuite/features/secondary/srv_rename_hostname.feature @@ -10,7 +10,7 @@ @skip_if_cloud @skip_if_container_server Feature: Reconfigure the server's hostname - As admin + As admin user In order to change the server's hostname I want to use the tool spacewalk-hostname-rename. @@ -18,16 +18,27 @@ Feature: Reconfigure the server's hostname Given I am authorized for the "Admin" section Scenario: Change hostname and reboot server - #Command prerequisites When I change the server's short hostname from hosts and hostname files And I reboot the server through SSH And I run spacewalk-hostname-rename command on the server - - Scenario: Change hostname back + + Scenario: Do some minimal smoke test on the renamed server + Given I am on the Systems overview page of this "sle_minion" + When I follow "Details" in the content area + And I follow "Remote Command" in the content area + And I enter as remote command this script in + """ + #!/bin/bash + date + """ + And I click on "Schedule" + And I follow "Events" in the content area + And I follow "Pending" in the content area + And I wait at most 180 seconds until I do not see "Remote Command on" text, refreshing the page + And I follow "History" in the content area + And I wait until I see the event "Remote Command on" completed during last minute, refreshing the page + + Scenario: Change hostname back and reboot server When I change back the server's hostname And I reboot the server through SSH And I run spacewalk-hostname-rename command on the server - - Scenario: Cleanup after hostname rename test - When I clean up the server's hosts file - And I restart the spacewalk service diff --git a/testsuite/features/step_definitions/command_steps.rb b/testsuite/features/step_definitions/command_steps.rb index 8931575170da..79db89c1024b 100644 --- a/testsuite/features/step_definitions/command_steps.rb +++ b/testsuite/features/step_definitions/command_steps.rb @@ -1455,18 +1455,19 @@ end end +# changing hostname When(/^I change the server's short hostname from hosts and hostname files$/) do server_node = get_target('server') old_hostname = server_node.hostname new_hostname = old_hostname + '2' - log "New short hostname: #{new_hostname}" + log "Old hostname: #{old_hostname} - New hostname: #{new_hostname}" server_node.run("sed -i 's/#{old_hostname}/#{new_hostname}/g' /etc/hostname && - echo '#{server_node.public_ip} #{server_node.full_hostname} #{old_hostname}' >> /etc/hosts && - echo '#{server_node.public_ip} #{new_hostname}#{server_node.full_hostname.delete_prefix(server_node.hostname)} #{new_hostname}' >> /etc/hosts") + hostname #{new_hostname} && + echo '#{server_node.public_ip} #{server_node.full_hostname} #{old_hostname}' >> /etc/hosts && + echo '#{server_node.public_ip} #{new_hostname}#{server_node.full_hostname.delete_prefix(server_node.hostname)} #{new_hostname}' >> /etc/hosts") get_target('server', refresh: true) # This will refresh the attributes of this node end -# changing hostname When(/^I run spacewalk-hostname-rename command on the server$/) do server_node = get_target('server') command = 'spacecmd --nossl -q api api.getVersion -u admin -p admin; ' \ @@ -1494,15 +1495,16 @@ When(/^I change back the server's hostname$/) do server_node = get_target('server') - server_node.run("echo '#{server_node.full_hostname}' > /etc/hostname ") + old_hostname = server_node.hostname + new_hostname = old_hostname.delete_suffix('2') + log "Old hostname: #{old_hostname} - New hostname: #{new_hostname}" + server_node.run("sed -i 's/#{old_hostname}/#{new_hostname}/g' /etc/hostname && + hostname #{new_hostname} && + sed -i \'$d\' /etc/hosts && + sed -i \'$d\' /etc/hosts") get_target('server', refresh: true) # This will refresh the attributes of this node end -When(/^I clean up the server's hosts file$/) do - command = 'sed -i \'$d\' /etc/hosts && sed -i \'$d\' /etc/hosts' - get_target('server').run(command) -end - When(/^I enable firewall ports for monitoring on this "([^"]*)"$/) do |host| add_ports = '' [9100, 9117, 9187].each do |port|