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

Add released updates. #17

Merged
merged 1 commit into from
Dec 16, 2022
Merged

Add released updates. #17

merged 1 commit into from
Dec 16, 2022

Conversation

varkoly
Copy link
Collaborator

@varkoly varkoly commented Sep 9, 2022

Problem

A lot of changes was made in my fork which are already released. Now I want to push it upstream

Copy link
Member

@lslezak lslezak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some ideas for improvements.

As this is for SP2 you can fix that only in master if you think it's too dangerous for a maintenance update.

field_name, value) unless value.is_a?(::String) && value.length == 2
integer_in_range(value, 0, 99, message, field_name)
def sap_instance_number(value, message = '', field_name = 'Instant Number')
message = "The SAP Instance number must be a string of exactly two digits " if message.nil? || message.empty?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Is the trailing space in the message OK?
  • Quoting is inconsistent, most of the code uses single quotes (`) , here are double quotes (")
    (In YaST we use double quotes, but I'm fine with single quotes, it just should be consistent.)

#expect of '*' and '/'. The identifier can be 256 character long
#However, for security and technical reasons, we only allow alphanumeric characters as well as '-' and '_'.
#The identifier must not be longer than 30 characters and it must be minimum 2 long.
IDENTIFIER_REGEXP = Regexp.new('^[a-zA-Z0-9][a-zA-Z0-9_\-]{1,29}$')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note: do not forget that in Ruby ^ means "start of line", not "start of the string" as usually...

global_ini.set_config('ha_dr_provider_SAPHanaSR', 'provider', 'SAPHanaSR')
global_ini.set_config('ha_dr_provider_SAPHanaSR', 'path', '/usr/share/SAPHanaSR')
global_ini.set_config('ha_dr_provider_SAPHanaSR', 'execution_order', '1')
global_ini.set_config('trace', 'ha_dr_saphanasr', 'info')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot of duplication from the previous method, maybe it would make sense to share the common part. But as this is for a maintenance update it would be more safe to do this only in the master branch:

def adjust_non_production_system(system_id, options = {})
  log.info "--- called #{self.class}.#{__callee__}(#{system_id}, #{options.inspect}) ---"
  adjust_system(system_id, options, 'non-production')
end

def adjust_production_system(system_id, options = {})
  log.info "--- called #{self.class}.#{__callee__}(#{system_id}, #{options.inspect}) ---"
  adjust_system(system_id, options, 'production') do |ini|
    ini.set_config('system_replication', 'preload_column_tables', options[:preload_column_tables])
  end
end

def adjust_system(system_id, options = {}, system_type = "", &block)
  # Change the global.ini
  global_ini_path = HANA_GLOBAL_INI % system_id.upcase
  unless File.exist?(global_ini_path)
    NodeLogger.error "Could not adjust global.ini for the #{system_type} system:"
    NodeLogger.output "File #{global_ini_path} does not exist"
    return false
  end
  begin
    global_ini = CFA::GlobalIni.new(global_ini_path)
    global_ini.load
    global_ini.set_config('memorymanager', 'global_allocation_limit', options[:global_alloc_limit])
    global_ini.set_config('ha_dr_provider_SAPHanaSR', 'provider', 'SAPHanaSR')
    global_ini.set_config('ha_dr_provider_SAPHanaSR', 'path', '/usr/share/SAPHanaSR')
    global_ini.set_config('ha_dr_provider_SAPHanaSR', 'execution_order', '1')
    global_ini.set_config('trace', 'ha_dr_saphanasr', 'info')

    block.call(global_ini) if block_given?

    global_ini.save
  rescue StandardError => e
    NodeLogger.error "Could not adjust global.ini for the #{system_type} system:"
    NodeLogger.output e.message
    return false
  else
    NodeLogger.info "Successfully adjusted global.ini for the #{system_type} system #{system_id}"
    true
  end
end

You can make the adjust_system method private.

Untested! Quick Hack! Please test it well!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've applied your suggestions in master.

@@ -112,7 +112,8 @@ def list_watchdogs
log.error "Could not find the kernel modules source directory #{MODULES_PATH}"
return []
end
Dir.glob(MODULES_PATH + '/*.ko').map { |path| File.basename(path, '.ko') }
wmods = Dir.glob(MODULES_PATH + '/*.ko*').map { |path| File.basename(path).gsub(/\.ko[\.\S+]*$/,'') }
wmods
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wmods is unused, you can remove that

@@ -139,4 +139,37 @@
expect(subject.ipv4_in_network_cidr('192.168.100.16', '192.168.100.0/28')).to eq false
end
end

describe 'SAP naming tests' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some notes:

  • describe should be used for methods, if you need to group some tests use context. (Technically it is irrelevant, one of them is just an alias to the other one, but it makes the tests better structured and more readable.)
  • describe should use a method name if possible/makes sense
  • you can put the repeating parts into before block
  • it should describe the action and the result

You can find more suggestions at https://www.betterspecs.org/

Proposal:

context 'SAP naming tests' do
  before do
    subject.silent = true
  end

  describe "#identifier" do
    it "returns true for valid IDs" do
      expect(subject.identifier('1Nuremberg')).to eq true
      expect(subject.identifier('1Nuremberg-A')).to eq true
      expect(subject.identifier('1Nuremberg_BA')).to eq true
      expect(subject.identifier('SuSE-1_2')).to eq true
    end

    it "returns false for invalid IDs" do
      expect(subject.identifier('Nürnberg')).to eq false
      expect(subject.identifier('-Nuremberg')).to eq false
      expect(subject.identifier('_Nuremberg')).to eq false
      expect(subject.identifier('*WalDorf-1_2/')).to eq false
      end
  end

  describe "#sap_sid" do
    it "returns true for valid IDs" do
      expect(subject.sap_sid('X12')).to eq true
    end

    it "returns false for invalid IDs" do
      expect(subject.sap_sid('123')).to eq false
      expect(subject.sap_sid('NOT')).to eq false
    end
  end

  describe "#sap_instance_number" do
    it "returns true for valid numbers" do
      expect(subject.sap_instance_number('05')).to eq true
      expect(subject.sap_instance_number('09')).to eq true
      expect(subject.sap_instance_number('10')).to eq true
      expect(subject.sap_instance_number('99')).to eq true
      end

    it "returns false for invalid numbers" do
      expect(subject.sap_instance_number('1')).to eq false
      expect(subject.sap_instance_number('1A')).to eq false
      expect(subject.sap_instance_number('999')).to eq false
      end
  end
end

Again, quick hack, please test it!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!
I've applied your suggestions in master.

@varkoly varkoly merged commit 9d39329 into yast:SLE-15-SP2 Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants