From 79360a844c8319de8879d2af57b9e152c07829a4 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Thu, 10 Oct 2019 14:56:39 -0400 Subject: [PATCH] Remove Timezone and Date and Time configuration Both of these can be done using the Cockpit UI https://bugzilla.redhat.com/show_bug.cgi?id=1745895 --- bin/appliance_console | 24 -- lib/manageiq-appliance_console.rb | 2 - lib/manageiq/appliance_console/cli.rb | 44 +--- .../date_time_configuration.rb | 117 --------- .../timezone_configuration.rb | 58 ----- locales/appliance/en.yml | 4 - locales/container/en.yml | 2 - spec/cli_spec.rb | 41 ---- spec/date_time_configuration_spec.rb | 228 ------------------ spec/timezone_configuration_spec.rb | 97 -------- 10 files changed, 1 insertion(+), 616 deletions(-) delete mode 100644 lib/manageiq/appliance_console/date_time_configuration.rb delete mode 100644 lib/manageiq/appliance_console/timezone_configuration.rb delete mode 100644 spec/date_time_configuration_spec.rb delete mode 100644 spec/timezone_configuration_spec.rb diff --git a/bin/appliance_console b/bin/appliance_console index baa58581d..3f3f211e5 100755 --- a/bin/appliance_console +++ b/bin/appliance_console @@ -296,30 +296,6 @@ Static Network Configuration end end - when I18n.t("advanced_settings.timezone") - say("#{selection}\n\n") - timezone_config = ManageIQ::ApplianceConsole::TimezoneConfiguration.new(timezone) - if timezone_config.ask_questions && timezone_config.activate - say("Timezone configured") - press_any_key - else - say("Timezone not configured") - press_any_key - raise MiqSignalError - end - - when I18n.t("advanced_settings.datetime") - say("#{selection}\n\n") - date_time_config = ManageIQ::ApplianceConsole::DateTimeConfiguration.new - if date_time_config.ask_questions && date_time_config.activate - say("Date and time configured") - press_any_key - else - say("Date and time not configured") - press_any_key - raise MiqSignalError - end - when I18n.t("advanced_settings.httpdauth") say("#{selection}\n\n") diff --git a/lib/manageiq-appliance_console.rb b/lib/manageiq-appliance_console.rb index a0d807bf2..f7a5109f0 100644 --- a/lib/manageiq-appliance_console.rb +++ b/lib/manageiq-appliance_console.rb @@ -35,7 +35,6 @@ def self.logger=(logger) require 'manageiq/appliance_console/database_replication' require 'manageiq/appliance_console/database_replication_primary' require 'manageiq/appliance_console/database_replication_standby' -require 'manageiq/appliance_console/date_time_configuration' require 'manageiq/appliance_console/external_auth_options' require 'manageiq/appliance_console/external_database_configuration' require 'manageiq/appliance_console/external_httpd_authentication' @@ -46,5 +45,4 @@ def self.logger=(logger) require 'manageiq/appliance_console/principal' require 'manageiq/appliance_console/scap' require 'manageiq/appliance_console/temp_storage_configuration' -require 'manageiq/appliance_console/timezone_configuration' require 'manageiq/appliance_console/utilities' diff --git a/lib/manageiq/appliance_console/cli.rb b/lib/manageiq/appliance_console/cli.rb index 8e3b24e75..54f0c8258 100644 --- a/lib/manageiq/appliance_console/cli.rb +++ b/lib/manageiq/appliance_console/cli.rb @@ -65,14 +65,6 @@ def log_disk? options[:logdisk] end - def time_zone? - options[:timezone] - end - - def date_time? - options[:datetime] - end - def extauth_opts? options[:extauth_opts] end @@ -141,8 +133,6 @@ def parse(args) opt :ipadomain, "IPA Server domain (optional)", :type => :string opt :iparealm, "IPA Server realm (optional)", :type => :string opt :ca, "CA name used for certmonger", :type => :string, :default => "ipa" - opt :timezone, "Time zone", :type => :string - opt :datetime, "Date and time, in YYYY-MM-DDTHH:MM:SS (ISO8601) format", :type => :string opt :http_cert, "install certs for http server", :type => :boolean opt :extauth_opts, "External Authentication Options", :type => :string opt :server, "{start|stop|restart} actions on evmserverd Server", :type => :string @@ -158,7 +148,7 @@ def region_number_required? def run Optimist.educate unless set_host? || key? || database? || tmp_disk? || log_disk? || uninstall_ipa? || install_ipa? || certs? || extauth_opts? || - time_zone? || date_time? || set_server_state? || set_replication? + set_server_state? || set_replication? if set_host? system_hosts = LinuxAdmin::Hosts.new system_hosts.hostname = options[:host] @@ -169,8 +159,6 @@ def run create_key if key? set_db if database? set_replication if set_replication? - set_time_zone if time_zone? - set_date_time if date_time? config_tmp_disk if tmp_disk? config_log_disk if log_disk? uninstall_ipa if uninstall_ipa? @@ -266,36 +254,6 @@ def set_replication db_replication.activate end - def set_time_zone - timezone_config = ManageIQ::ApplianceConsole::TimezoneConfiguration.new(options[:timezone]) - timezone_config.new_timezone = options[:timezone] - if timezone_config.activate - say("Timezone configured") - else - say("Timezone not configured") - end - end - - def set_date_time - date_time_config = ManageIQ::ApplianceConsole::DateTimeConfiguration.new - unless options[:datetime] == "auto" - date_time_config.manual_time_sync = true - date_time_config.new_date, date_time_config.new_time = options[:datetime].split("T") - return unless date_time_valid?(date_time_config) - end - date_time_config.activate - end - - def date_time_valid?(date_time_config) - unless ManageIQ::ApplianceConsole::DateTimeConfiguration::DATE_REGEXP =~ date_time_config.new_date && - ManageIQ::ApplianceConsole::DateTimeConfiguration::TIME_REGEXP =~ date_time_config.new_time - say("Datetime should be given in YYYY-MM-DDTHH:MM:SS format") - say("Datetime not configured") - return false - end - true - end - def key_configuration @key_configuration ||= KeyConfiguration.new( :action => options[:fetch_key] ? :fetch : :create, diff --git a/lib/manageiq/appliance_console/date_time_configuration.rb b/lib/manageiq/appliance_console/date_time_configuration.rb deleted file mode 100644 index f59418ada..000000000 --- a/lib/manageiq/appliance_console/date_time_configuration.rb +++ /dev/null @@ -1,117 +0,0 @@ -module ManageIQ -module ApplianceConsole - class DateTimeConfiguration - DATE_REGEXP = /^(2[0-9]{3})-(0?[1-9]|1[0-2])-(0?[1-9]|[12][0-9]|3[01])/ - DATE_PROMPT = "current date (YYYY-MM-DD)".freeze - TIME_REGEXP = /^(0?[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])/ - TIME_PROMPT = "current time in 24 hour format (HH:MM:SS)".freeze - - attr_accessor :new_date, :new_time, :manual_time_sync - - include ManageIQ::ApplianceConsole::Logging - - def initialize - @new_date = nil - @new_time = nil - @manual_time_sync = false - end - - def activate - say("Applying time configuration...") - establish_auto_sync && - configure_date_time - end - - def ask_questions - ask_establish_auto_sync - ask_for_date && - ask_for_time && - confirm - end - - def ask_establish_auto_sync - say("Automatic time synchronization must be disabled to manually set date or time\n\n") - - @manual_time_sync = agree(<<-EOL) -Yes to disable Automatic time synchronization and prompt for date and time. - No to enable Automatic time synchronization. (Y/N): - - EOL - end - - def ask_for_date - return true unless manual_time_sync - @new_date = just_ask(DATE_PROMPT, nil, DATE_REGEXP) - true - rescue - false - end - - def ask_for_time - return true unless manual_time_sync - @new_time = just_ask(TIME_PROMPT, nil, TIME_REGEXP) - true - rescue - false - end - - def confirm - manual_time_sync ? confirm_manual : confirm_auto - end - - def confirm_auto - clear_screen - say("Date and Time Configuration will be automatic") - - agree("Apply automatic time configuration? (Y/N): ") - end - - def confirm_manual - clear_screen - say(<<-EOL) -Date and Time Configuration - - Date: #{new_date} - Time: #{new_time} - - EOL - - agree("Apply manual time configuration? (Y/N): ") - end - - def establish_auto_sync - manual_time_sync ? disable_auto_sync : enable_auto_sync - end - - def enable_auto_sync - LinuxAdmin::Service.new("chronyd").enable.start - LinuxAdmin::Service.new("systemd-timedated").restart - true - rescue => e - say("Failed to enable time synchronization") - logger.error("Failed to enable time synchronization: #{e.message}") - false - end - - def disable_auto_sync - LinuxAdmin::Service.new("chronyd").stop.disable - LinuxAdmin::Service.new("systemd-timedated").restart - true - rescue => e - say("Failed to disable time synchronization") - logger.error("Failed to disable time synchronization: #{e.message}") - false - end - - def configure_date_time - return true unless manual_time_sync - LinuxAdmin::TimeDate.system_time = Time.parse("#{new_date} #{new_time}").getlocal - true - rescue => e - say("Failed to apply time configuration") - logger.error("Failed to apply time configuration: #{e.message}") - false - end - end # class DateTimeConfiguration -end # module ApplianceConsole -end diff --git a/lib/manageiq/appliance_console/timezone_configuration.rb b/lib/manageiq/appliance_console/timezone_configuration.rb deleted file mode 100644 index 55b1c90ed..000000000 --- a/lib/manageiq/appliance_console/timezone_configuration.rb +++ /dev/null @@ -1,58 +0,0 @@ -require "linux_admin" - -module ManageIQ -module ApplianceConsole - class TimezoneConfiguration - include ManageIQ::ApplianceConsole::Logging - - attr_reader :current_timzone - attr_accessor :new_timezone - - def initialize(region_timezone_string) - @current_timezone = region_timezone_string - end - - def activate - log_and_feedback(__method__) do - say("Applying new timezone #{new_timezone}...") - begin - LinuxAdmin::TimeDate.system_timezone = new_timezone - rescue LinuxAdmin::TimeDate::TimeCommandError => e - say("Failed to apply timezone configuration") - logger.error("Failed to timezone configuration: #{e.message}") - return false - end - end - true - end - - def ask_questions - ask_for_timezone && confirm - end - - def ask_for_timezone - current_item = timezone_hash - - while current_item.is_a?(Hash) - selection = ask_with_menu("Geographic Location", current_item.keys, nil, false) - return false if selection == CANCEL - current_item = current_item[selection] - end - - @new_timezone = current_item - true - end - - def confirm - clear_screen - agree("Change the timezone to #{new_timezone}? (Y/N): ") - end - - def timezone_hash - LinuxAdmin::TimeDate.timezones.each_with_object({}) do |tz, hash| - hash.store_path(*tz.split("/"), tz) - end - end - end # class TimezoneConfiguration -end # module ApplianceConsole -end diff --git a/locales/appliance/en.yml b/locales/appliance/en.yml index c2b769254..f25dee12c 100644 --- a/locales/appliance/en.yml +++ b/locales/appliance/en.yml @@ -5,8 +5,6 @@ en: advanced_settings: menu_order: - networking - - timezone - - datetime - dbbackup - dbdump - dbrestore @@ -24,8 +22,6 @@ en: - summary - quit networking: Configure Network - timezone: Set Timezone - datetime: Set Date and Time dbbackup: Create Database Backup dbdump: Create Database Dump dbrestore: Restore Database From Backup diff --git a/locales/container/en.yml b/locales/container/en.yml index 5065dec18..362e092ec 100644 --- a/locales/container/en.yml +++ b/locales/container/en.yml @@ -4,7 +4,6 @@ en: name: ManageIQ advanced_settings: menu_order: - - timezone - dbrestore - db_config - db_replication @@ -15,7 +14,6 @@ en: - shutdown - summary - quit - timezone: Set Timezone dbrestore: Restore Database From Backup db_config: Configure Database db_replication: Configure Database Replication diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index 2ab7ca79b..2b7cdd32e 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -651,47 +651,6 @@ end end - context "#set_time_zone" do - let(:timezone) { double("time zone") } - it "should set timezone" do - expect(subject).to receive(:say) - expect(ManageIQ::ApplianceConsole::TimezoneConfiguration).to receive(:new).with("Europe/Madrid").and_return(timezone) - expect(timezone).to receive(:new_timezone=).with("Europe/Madrid") - expect(timezone).to receive(:activate).and_return(true) - subject.parse(%w(--timezone Europe/Madrid)).run - end - - it "should not set timezone" do - expect(subject).to receive(:say) - expect(ManageIQ::ApplianceConsole::TimezoneConfiguration).to receive(:new).with("ss/dd").and_return(timezone) - expect(timezone).to receive(:new_timezone=).with("ss/dd") - expect(timezone).to receive(:activate).and_return(false) - subject.parse(%w(--timezone ss/dd)).run - end - end - - context "#set_date_time" do - let(:datetime) { ManageIQ::ApplianceConsole::DateTimeConfiguration.new } - - before do - expect(ManageIQ::ApplianceConsole::DateTimeConfiguration).to receive(:new).and_return(datetime) - end - - it "should set auto sync when datetime option is auto" do - expect(datetime).to receive(:activate).and_return(true) - subject.parse(%w(--datetime auto)).run - expect(datetime.manual_time_sync).to be_falsy - end - - it "should set date time according to given date time" do - expect(datetime).to receive(:activate).and_return(true) - subject.parse(%w(--datetime 2017-06-08T09:00:00)).run - expect(datetime.manual_time_sync).to be_truthy - expect(datetime.new_date).to eq("2017-06-08") - expect(datetime.new_time).to eq("09:00:00") - end - end - context "#disk_from_string" do before do allow(LinuxAdmin::Disk).to receive_messages(:local => [ diff --git a/spec/date_time_configuration_spec.rb b/spec/date_time_configuration_spec.rb deleted file mode 100644 index 3b8c65c7c..000000000 --- a/spec/date_time_configuration_spec.rb +++ /dev/null @@ -1,228 +0,0 @@ -describe ManageIQ::ApplianceConsole::DateTimeConfiguration do - subject { described_class.new } - - before do - allow(subject).to receive(:say) - allow(subject).to receive(:clear_screen) - allow(subject).to receive(:agree) - end - - context "#ask_questions" do - it "returns true when all user input is provided" do - expect(subject).to receive(:ask_establish_auto_sync).and_return(true) - expect(subject).to receive(:ask_for_date).and_return(true) - expect(subject).to receive(:ask_for_time).and_return(true) - expect(subject).to receive(:confirm).and_return(true) - expect(subject.ask_questions).to be true - end - - it "returns false when apply date time is canceled" do - expect(subject).to receive(:ask_establish_auto_sync).and_return(true) - expect(subject).to receive(:ask_for_date).and_return(true) - expect(subject).to receive(:ask_for_time).and_return(true) - expect(subject).to receive(:confirm).and_return(false) - expect(subject.ask_questions).to be false - end - - it "returns false when new time is canceled" do - expect(subject).to receive(:ask_establish_auto_sync).and_return(true) - expect(subject).to receive(:ask_for_date).and_return(true) - expect(subject).to receive(:ask_for_time).and_return(false) - expect(subject).to_not receive(:confirm) - expect(subject.ask_questions).to be false - end - - it "returns false when new date is canceled" do - expect(subject).to receive(:ask_establish_auto_sync).and_return(true) - expect(subject).to receive(:ask_for_date).and_return(false) - expect(subject).to_not receive(:ask_for_time) - expect(subject).to_not receive(:confirm) - expect(subject.ask_questions).to be false - end - - it "Continues asking when disable auto sync returns false" do - expect(subject).to receive(:ask_establish_auto_sync).and_return(false) - expect(subject).to receive(:ask_for_date).and_return(true) - expect(subject).to receive(:ask_for_time).and_return(true) - expect(subject).to receive(:confirm).and_return(true) - expect(subject.ask_questions).to be true - end - end - - context "#ask_establish_auto_sync" do - it "asks confirmation to disable auto sync" do - expect(subject).to receive(:agree).and_return(true) - expect(subject.ask_establish_auto_sync).to be true - expect(subject.manual_time_sync).to be true - end - - it "returns false when automatic time sycn is requested" do - allow(subject).to receive(:agree).and_return(false) - expect(subject.ask_establish_auto_sync).to be false - expect(subject.manual_time_sync).to be false - end - end - - context "#ask_for_date" do - it "asks for a new date" do - subject.instance_variable_set(:@manual_time_sync, true) - expect(subject).to receive(:just_ask).and_return('2000-01-01') - expect(subject.ask_for_date).to be true - expect(subject.new_date).to eq('2000-01-01') - end - - it "Does not asks for a new date when auto time sync" do - subject.instance_variable_set(:@manual_time_sync, false) - expect(subject).to_not receive(:just_ask) - expect(subject.ask_for_date).to be true - end - - it "returns false when cancel is requested" do - subject.instance_variable_set(:@manual_time_sync, true) - expect { subject.just_ask }.to raise_error(StandardError) - expect(subject.ask_for_date).to be false - end - end - - context "#ask_for_time" do - it "asks for a new time " do - subject.instance_variable_set(:@manual_time_sync, true) - expect(subject).to receive(:just_ask).and_return('01:23:45') - expect(subject.ask_for_time).to be true - expect(subject.new_time).to eq('01:23:45') - end - - it "Does not asks for a new time when auto time sync" do - subject.instance_variable_set(:@manual_time_sync, false) - expect(subject).to_not receive(:just_ask) - expect(subject.ask_for_time).to be true - end - - it "returns false when cancel is requested" do - subject.instance_variable_set(:@manual_time_sync, true) - expect { subject.just_ask }.to raise_error(StandardError) - expect(subject.ask_for_time).to be false - end - end - - context "#confirm_manual" do - before do - subject.instance_variable_set(:@new_date, '2000-01-01') - subject.instance_variable_set(:@new_time, '01:23:45') - subject.instance_variable_set(:@manual_time_sync, false) - end - - it "asks to apply manual date / time" do - expect(subject).to receive(:agree).and_return(true) - expect(subject.confirm).to be true - end - - it "returns false when cancel is requested" do - expect(subject).to receive(:agree).and_return(false) - expect(subject.confirm).to be false - end - end - - context "#confirm_auto" do - before do - subject.instance_variable_set(:@manual_time_sync, true) - end - - it "asks to apply automatic date / time" do - expect(subject).to receive(:agree).and_return(true) - expect(subject.confirm).to be true - end - - it "returns false when cancel is requested" do - expect(subject).to receive(:agree).and_return(false) - expect(subject.confirm).to be false - end - end - - context "#disable_auto_sync" do - before do - subject.instance_variable_set(:@manual_time_sync, true) - end - - it "Disables auto time and date synchronization" do - expect(LinuxAdmin::Service).to receive(:new).and_return(double(:stop => double(:disable => nil))) - expect(LinuxAdmin::Service).to receive(:new).and_return(double(:restart => nil)) - expect(subject.establish_auto_sync).to be true - end - - it "returns false when a failure is detected" do - expect(LinuxAdmin::Service).to receive(:new).and_raise("Error") - expect(subject.establish_auto_sync).to be false - end - end - - context "#enable_auto_sync" do - before do - subject.instance_variable_set(:@manual_time_sync, false) - end - - it "enables auto time and date synchronization" do - expect(LinuxAdmin::Service).to receive(:new).and_return(double(:enable => double(:start => nil))) - expect(LinuxAdmin::Service).to receive(:new).and_return(double(:restart => nil)) - expect(subject.establish_auto_sync).to be true - end - - it "returns false when a failure is detected" do - expect(LinuxAdmin::Service).to receive(:new).and_raise("Error") - expect(subject.establish_auto_sync).to be false - end - end - - context "#configure_date_time" do - it "cofigures the system date and time" do - subject.instance_variable_set(:@manual_time_sync, true) - expect(Time).to receive(:parse).and_return(double(:getlocal => nil)) - expect(LinuxAdmin::TimeDate).to receive(:system_time=).and_return(nil) - expect(subject.configure_date_time).to be true - end - - it "does not cofigures the system date and time when auto sync" do - subject.instance_variable_set(:@manual_time_sync, false) - expect(Time).to_not receive(:parse) - expect(LinuxAdmin::TimeDate).to_not receive(:system_time=) - expect(subject.configure_date_time).to be true - end - - it "returns false when a failure is detected" do - subject.instance_variable_set(:@manual_time_sync, true) - expect(Time).to receive(:parse).and_return(double(:getlocal => nil)) - expect(LinuxAdmin::TimeDate).to receive(:system_time=).and_raise("Error") - expect(subject.configure_date_time).to be false - end - end - - context "#activate" do - before do - allow(subject).to receive(:say) - end - - it "returns true when auto sync and configure succeed" do - expect(subject).to receive(:establish_auto_sync).and_return(true) - expect(subject).to receive(:configure_date_time).and_return(true) - expect(subject.activate).to be true - end - - it "returns false when configure is canceled" do - expect(subject).to receive(:establish_auto_sync).and_return(true) - expect(subject).to receive(:configure_date_time).and_return(false) - expect(subject.activate).to be false - end - - it "returns false when establish auto sync fails" do - expect(subject).to receive(:establish_auto_sync).and_return(false) - expect(subject).to_not receive(:configure_date_time) - expect(subject.activate).to be false - end - - it "returns false when configure date time fails" do - expect(subject).to receive(:establish_auto_sync).and_return(true) - expect(subject).to receive(:configure_date_time).and_return(false) - expect(subject.activate).to be false - end - end -end diff --git a/spec/timezone_configuration_spec.rb b/spec/timezone_configuration_spec.rb deleted file mode 100644 index a467e704b..000000000 --- a/spec/timezone_configuration_spec.rb +++ /dev/null @@ -1,97 +0,0 @@ -describe ManageIQ::ApplianceConsole::TimezoneConfiguration do - subject { described_class.new('US/Eastern') } - - let(:timezone_hash) do - { - "Africa" => { - "Abidijan" => "Africa/Abidijan" - }, - "America" => { - "Argentina" => { - "Buenos_Aires" => "America/Argentina/Buenos_Aires" - } - }, - "UTC" => "UTC" - } - end - - describe "#ask_questions" do - it "returns true when all user input is provided" do - expect(subject).to receive(:ask_for_timezone).and_return(true) - expect(subject).to receive(:confirm).and_return(true) - expect(subject.ask_questions).to be true - end - end - - describe "#ask_for_timezone" do - before do - expect(subject).to receive(:timezone_hash).and_return(timezone_hash) - end - - it "prompts once for non-nested timezones" do - expect(subject).to receive(:ask_with_menu).once - .with("Geographic Location", %w(Africa America UTC), nil, false) - .and_return("UTC") - - expect(subject.ask_for_timezone).to be true - - expect(subject.new_timezone).to eq("UTC") - end - - it "prompts multiple times for nested timezones" do - expect(subject).to receive(:ask_with_menu) - .with("Geographic Location", %w(Africa America UTC), nil, false) - .and_return("America").ordered - expect(subject).to receive(:ask_with_menu) - .with("Geographic Location", ["Argentina"], nil, false) - .and_return("Argentina").ordered - expect(subject).to receive(:ask_with_menu) - .with("Geographic Location", ["Buenos_Aires"], nil, false) - .and_return("Buenos_Aires").ordered - - expect(subject.ask_for_timezone).to be true - - expect(subject.new_timezone).to eq("America/Argentina/Buenos_Aires") - end - end - - describe "#confirm" do - before do - allow(subject).to receive(:clear_screen) - end - - it "asks to apply timezone" do - expect(subject).to receive(:agree).and_return(true) - expect(subject.confirm).to be true - end - - it "returns false when cancel is requested" do - expect(subject).to receive(:agree).and_return(false) - expect(subject.confirm).to be false - end - end - - describe "#activate" do - before do - expect(subject).to receive(:log_and_feedback).and_yield - allow(subject).to receive(:say) - end - - it "Applies the requested timezone" do - expect(LinuxAdmin::TimeDate).to receive(:system_timezone=) - expect(subject.activate).to be_truthy - end - - it "returns false on failure" do - expect(LinuxAdmin::TimeDate).to receive(:system_timezone=).and_raise(LinuxAdmin::TimeDate::TimeCommandError) - expect(subject.activate).to be_falsy - end - end - - describe "#timezone_hash" do - it "returns the correct hash" do - expect(LinuxAdmin::TimeDate).to receive(:timezones).and_return(%w(Africa/Abidijan UTC America/Argentina/Buenos_Aires)) - expect(subject.timezone_hash).to eq(timezone_hash) - end - end -end