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

Fix hostname rename feature #7474

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions testsuite/features/secondary/srv_rename_hostname.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,35 @@
@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.

Scenario: Log in as admin user
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
22 changes: 12 additions & 10 deletions testsuite/features/step_definitions/command_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
nodeg marked this conversation as resolved.
Show resolved Hide resolved
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; ' \
Expand Down Expand Up @@ -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|
Expand Down