Skip to content

Commit

Permalink
Use libyu api for yast2 lan dhcp hostname setting
Browse files Browse the repository at this point in the history
The commit rewrites yast2_lan_hostname tests to use libyui-rest-api.

Also the test cases are separated for the cases when 'no', 'yes: any'
and 'yes: eth0' are set for hostname via DHCP.

Related ticket: https://progress.opensuse.org/issues/89209
  • Loading branch information
Oleksandr Orlov committed Mar 12, 2021
1 parent cddbcb0 commit cd23eb0
Show file tree
Hide file tree
Showing 21 changed files with 539 additions and 35 deletions.
43 changes: 43 additions & 0 deletions lib/YaST/Module.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# SUSE's openQA tests
#
# Copyright © 2021 SUSE LLC
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.

# Summary: The class introduces methods that are common for all YaST modules.
# Maintainer: QE YaST <qa-sle-yast@suse.de>

package YaST::Module;
use strict;
use warnings;
use testapi;
use YuiRestClient;
use y2_module_guitest qw(launch_yast2_module_x11);
use y2_module_consoletest qw(yast2_console_exec);

sub open {
my ($args) = @_;
my $module = $args->{module};
my $ui = $args->{ui};
die 'No module name specified.' unless defined $module;
die 'No user interface specified.' unless defined $ui;
if (lc($ui) eq 'ncurses') {
y2_module_consoletest::yast2_console_exec(
yast2_module => $module,
yast2_opts => '--ncurses',
extra_vars => get_var('YUI_PARAMS')
);
}
elsif (lc($ui) eq 'qt') {
launch_yast2_module_x11('', $module, extra_vars => get_var('YUI_PARAMS'));
}
else {
die "Unknown user interface: $ui";
}
YuiRestClient::connect_to_app_running_system();
}

1;
19 changes: 11 additions & 8 deletions lib/YaST/NetworkSettings/AbstractNetworkSettingsController.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ use YaST::NetworkSettings::NetworkCardSetup::VLANAddressTab;

sub new {
my ($class, $args) = @_;
my $self = bless {
OverviewTab => YaST::NetworkSettings::OverviewTab->new(),
AddressTab => YaST::NetworkSettings::NetworkCardSetup::AddressTab->new(),
GeneralTab => YaST::NetworkSettings::NetworkCardSetup::GeneralTab->new(),
VLANAddressTab => YaST::NetworkSettings::NetworkCardSetup::VLANAddressTab->new()
}, $class;
my $self = bless {}, $class;
return $self->init($args);
}

sub init {
my ($self, $args) = @_;
$self->{OverviewTab} = YaST::NetworkSettings::OverviewTab->new();
$self->{AddressTab} = YaST::NetworkSettings::NetworkCardSetup::AddressTab->new();
$self->{GeneralTab} = YaST::NetworkSettings::NetworkCardSetup::GeneralTab->new();
$self->{VLANAddressTab} = YaST::NetworkSettings::NetworkCardSetup::VLANAddressTab->new();
return $self;
}

sub get_overview_tab {
Expand Down Expand Up @@ -151,6 +156,4 @@ sub save_changes {
$self->get_overview_tab()->press_ok();
}



1;
38 changes: 38 additions & 0 deletions lib/YaST/NetworkSettings/ActionButtons.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# SUSE's openQA tests
#
# Copyright © 2021 SUSE LLC
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.

# Summary: The class introduces all accessing methods cction buttons in yast2 lan YaST module.
# The buttons in the bottom of the screen that are available across all the pages (e.g. "Next", "Cancel");
# This is a part of a screen and it has to be included in Network Settings Controller.
# Maintainer: QE YaST <qa-sle-yast@suse.de>

package YaST::NetworkSettings::ActionButtons;
use strict;
use warnings;

sub new {
my ($class, $args) = @_;
my $self = bless {
app => $args->{app}
}, $class;
return $self->init();
}

sub init {
my $self = shift;
$self->{btn_ok} = $self->{app}->button({id => 'next'});
return $self;
}

sub press_ok {
my ($self) = @_;
$self->{btn_ok}->click();
}

1;
37 changes: 37 additions & 0 deletions lib/YaST/NetworkSettings/HostnameDNSTab.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SUSE's openQA tests
#
# Copyright © 2021 SUSE LLC
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.

# Summary: The class introduces all accessing methods for Hostname/DNS Tab in YaST2
# lan module dialog.
# Maintainer: QE YaST <qa-sle-yast@suse.de>

package YaST::NetworkSettings::HostnameDNSTab;
use strict;
use warnings;

sub new {
my ($class, $args) = @_;
my $self = bless {
app => $args->{app}
}, $class;
return $self->init();
}

sub init {
my $self = shift;
$self->{cb_set_hostname_via_dhcp} = $self->{app}->combobox({id => '"DHCP_HOSTNAME"'});
return $self;
}

sub select_option_in_hostname_via_dhcp {
my ($self, $option) = @_;
$self->{cb_set_hostname_via_dhcp}->select($option);
}

1;
37 changes: 37 additions & 0 deletions lib/YaST/NetworkSettings/TopNavigationBar.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SUSE's openQA tests
#
# Copyright © 2021 SUSE LLC
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.

# Summary: The class introduces all accessing methods Top Navigation Bar in yast2 lan YaST module.
# This is a part of a screen and it has to be included in Network Settings Controller.
# Maintainer: QE YaST <qa-sle-yast@suse.de>

package YaST::NetworkSettings::TopNavigationBar;
use strict;
use warnings;

sub new {
my ($class, $args) = @_;
my $self = bless {
app => $args->{app}
}, $class;
return $self->init();
}

sub init {
my $self = shift;
$self->{menu_bar} = $self->{app}->menucollection({id => '_cwm_tab'});
return $self;
}

sub select_hostname_dns_tab {
my ($self) = @_;
$self->{menu_bar}->select('Ho&stname/DNS');
}

1;
8 changes: 7 additions & 1 deletion lib/YaST/NetworkSettings/v3/NetworkSettingsController.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ use YaST::NetworkSettings::NetworkCardSetup::BondSlavesTab;

sub new {
my ($class, $args) = @_;
my $self = $class->SUPER::new($args);
my $self = bless {}, $class;
return $self->init($args);
}

sub init {
my ($self, $args) = @_;
$self->SUPER::init($args);
$self->{HardwareDialog} = YaST::NetworkSettings::NetworkCardSetup::HardwareDialog->new();
$self->{BridgedDevicesTab} = YaST::NetworkSettings::NetworkCardSetup::BridgedDevicesTab->new({tab_shortcut => 'alt-i', bridged_devices_shortcut => 'alt-d'});
$self->{BondSlavesTab} = YaST::NetworkSettings::NetworkCardSetup::BondSlavesTab->new({tab_shortcut => 'alt-o'});
Expand Down
8 changes: 7 additions & 1 deletion lib/YaST/NetworkSettings/v4/NetworkSettingsController.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ use YaST::NetworkSettings::NetworkCardSetup::BondSlavesTab;

sub new {
my ($class, $args) = @_;
my $self = $class->SUPER::new($args);
my $self = bless {}, $class;
return $self->init($args);
}

sub init {
my ($self, $args) = @_;
$self->SUPER::init($args);
$self->{DeviceTypeDialog} = YaST::NetworkSettings::NetworkCardSetup::DeviceTypeDialog->new();
$self->{BridgedDevicesTabOnAdd} = YaST::NetworkSettings::NetworkCardSetup::BridgedDevicesTab->new({tab_shortcut => 'alt-v', bridged_devices_shortcut => 'alt-i'});
$self->{BridgedDevicesTabOnEdit} = YaST::NetworkSettings::NetworkCardSetup::BridgedDevicesTab->new({tab_shortcut => 'alt-b', bridged_devices_shortcut => 'alt-i'});
Expand Down
54 changes: 53 additions & 1 deletion lib/YaST/NetworkSettings/v4_3/NetworkSettingsController.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,46 @@ package YaST::NetworkSettings::v4_3::NetworkSettingsController;
use parent 'YaST::NetworkSettings::v4::NetworkSettingsController';
use strict;
use warnings;
use YaST::NetworkSettings::TopNavigationBar;
use YaST::NetworkSettings::HostnameDNSTab;
use YaST::NetworkSettings::ActionButtons;
use YaST::Warning::Notification;
use YuiRestClient;

sub new {
my ($class, $args) = @_;
return $class->SUPER::new($args);
my $self = bless {}, $class;
return $self->init($args);
}

sub init {
my ($self, $args) = @_;
$self->SUPER::init($args);
$self->{TopNavigationBar} = YaST::NetworkSettings::TopNavigationBar->new({app => YuiRestClient::get_app()});
$self->{HostnameDNSTab} = YaST::NetworkSettings::HostnameDNSTab->new({app => YuiRestClient::get_app()});
$self->{ActionButtons} = YaST::NetworkSettings::ActionButtons->new({app => YuiRestClient::get_app()});
$self->{NotificationWarning} = YaST::Warning::Notification->new({app => YuiRestClient::get_app()});
return $self;
}

sub get_top_navigation_bar {
my ($self) = @_;
return $self->{TopNavigationBar};
}

sub get_hostname_dns_tab {
my ($self) = @_;
return $self->{HostnameDNSTab};
}

sub get_action_buttons {
my ($self) = @_;
return $self->{ActionButtons};
}

sub get_notification_warning {
my ($self) = @_;
return $self->{NotificationWarning};
}

sub view_bond_slave_without_editing {
Expand All @@ -29,4 +65,20 @@ sub view_bond_slave_without_editing {
$self->get_bond_slaves_tab_on_edit()->press_next();
}

sub set_hostname_via_dhcp {
my ($self, $args) = @_;
my $dhcp_option = $args->{dhcp_option};
my $confirm_warning = $args->{confirm_warning};
if ($confirm_warning) {
$self->get_notification_warning()->confirm();
}
$self->get_top_navigation_bar()->select_hostname_dns_tab();
$self->get_hostname_dns_tab()->select_option_in_hostname_via_dhcp($dhcp_option);
}

sub save_changes {
my ($self) = @_;
$self->get_action_buttons()->press_ok();
}

1;
52 changes: 52 additions & 0 deletions lib/YaST/Warning/Notification.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# SUSE's openQA tests
#
# Copyright © 2021 SUSE LLC
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.

# Summary: The class introduces methods in Expert Partitioner to handle
# a Warning Dialog.
# Maintainer: QE YaST <qa-sle-yast@suse.de>

package YaST::Warning::Notification;
use strict;
use warnings;

sub new {
my ($class, $args) = @_;
my $self = bless {
app => $args->{app}
}, $class;
return $self->init();
}

sub init {
my $self = shift;
$self->{btn_ok} = $self->{app}->button({id => 'ok_msg'});
$self->{lbl_header} = $self->{app}->label({label => 'Warning'});
$self->{lbl_warning} = $self->{app}->label({type => 'YLabel'});
return $self;
}

sub confirm {
my ($self) = @_;
YuiRestClient::Wait::wait_until(object => sub {
$self->is_shown();
});
$self->press_ok();
}

sub press_ok {
my ($self) = @_;
$self->{btn_ok}->click();
}

sub is_shown {
my ($self) = @_;
$self->{lbl_header}->exist();
}

1;
8 changes: 6 additions & 2 deletions lib/YuiRestClient.pm
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,19 @@ sub setup_libyui {
}

sub setup_libyui_running_system {
add_suseconnect_product('sle-module-development-tools');
zypper_call('in libyui-rest-api');

my $port = get_var('YUI_PORT');
my $host = get_var('YUI_SERVER');
record_info('PORT', "Used port for libyui: $port");
record_info('SERVER', "Connecting to: $host");
set_var('YUI_PARAMS', "YUI_HTTP_PORT=$port YUI_HTTP_REMOTE=1 YUI_REUSE_PORT=1");
assert_script_run("firewall-cmd --zone=public --add-port=$port/tcp");
# Add the port to permanent config and restart firewalld to apply the changes immediately.
# This is needed, because if firewall is restarted for some reason, then the port become
# closed (e.g. it was faced while saving settings in yast2 lan) and further tests will not
# be able to communicate with YaST modules.
assert_script_run("firewall-cmd --zone=public --add-port=$port/tcp --permanent");
assert_script_run('firewall-cmd --reload');
my $app = YuiRestClient::App->new({port => $port, host => $host, api_version => API_VERSION});
set_app($app);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/y2_module_consoletest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ use strict;
use warnings;
use testapi;
use Utils::Backends 'is_hyperv';
use Exporter 'import';
our @EXPORT_OK = qw(yast2_console_exec);

sub yast2_console_exec {
my %args = @_;
die "Yast2 module has not been found among function arguments!\n" unless (defined($args{yast2_module}));
my $y2_start = y2_module_basetest::with_yast_env_variables() . ' yast2 ';
my $y2_start = y2_module_basetest::with_yast_env_variables($args{extra_vars}) . ' yast2 ';
my $module_name = 'yast2-' . $args{yast2_module} . '-status';
$y2_start .= (defined($args{yast2_opts})) ?
$args{yast2_opts} . ' ' . $args{yast2_module} :
Expand Down

0 comments on commit cd23eb0

Please sign in to comment.