From 86659f81fb43f2b8a89a8e9c50e50feef75cb3e6 Mon Sep 17 00:00:00 2001 From: Kamil Szubrycht Date: Wed, 5 Apr 2023 13:29:53 +0200 Subject: [PATCH] Use theforeman-rubocop (#99) * Bump actions * Use theforeman-rubocop gem * Rubocopo auto-correct * Rupocop auto-gen-config --- .github/workflows/ci.yml | 31 +++------ .rubocop.yml | 57 ++++------------ .rubocop_todo.yml | 67 +++++++++++++++++++ .../foreman_netbox/delete_host/organizer.rb | 2 +- .../foreman_netbox/sync_host/organizer.rb | 2 +- .../sync_host/sync_device/find.rb | 2 - .../sync_host/sync_device/organizer.rb | 20 +++--- .../sync_device/sync_device_role/organizer.rb | 2 +- .../sync_device/sync_device_type/organizer.rb | 6 +- .../sync_manufacturer/find.rb | 5 +- .../sync_manufacturer/organizer.rb | 2 +- .../sync_device/sync_interfaces/find.rb | 2 +- .../sync_device/sync_interfaces/organizer.rb | 8 +-- .../sync_ip_addresses/delete.rb | 4 +- .../sync_interfaces/sync_ip_addresses/find.rb | 2 +- .../sync_ip_addresses/organizer.rb | 6 +- .../sync_device/sync_interfaces/update.rb | 4 +- .../sync_device/sync_site/organizer.rb | 4 +- .../sync_host/sync_tags/organizer.rb | 4 +- .../sync_host/sync_tenant/organizer.rb | 4 +- .../sync_host/sync_virtual_machine/find.rb | 2 - .../sync_virtual_machine/organizer.rb | 16 ++--- .../sync_cluster/organizer.rb | 6 +- .../sync_cluster_type/organizer.rb | 2 +- .../sync_interfaces/find.rb | 2 +- .../sync_interfaces/organizer.rb | 8 +-- .../sync_ip_addresses/delete.rb | 4 +- .../sync_interfaces/sync_ip_addresses/find.rb | 2 +- .../sync_ip_addresses/organizer.rb | 6 +- .../sync_interfaces/update.rb | 4 +- app/models/orchestration/netbox.rb | 6 +- .../cached_netbox_parameters.rb | 22 +++--- .../foreman_netbox/netbox_parameters.rb | 54 +++++++-------- .../netbox_parameters_comparator.rb | 18 +++-- foreman_netbox.gemspec | 3 +- lib/foreman_netbox/engine.rb | 40 +++++------ lib/tasks/foreman_netbox_tasks.rake | 2 - .../sync_k8s_physical_host_test.rb | 14 ++-- .../sync_rhel_physical_host_test.rb | 14 ++-- .../sync_rhel_virtual_host_test.rb | 14 ++-- .../sync_host/organizer_test.rb | 18 ++--- .../sync_host/sync_device/create_test.rb | 2 +- .../sync_device_role/create_test.rb | 2 +- .../sync_device/sync_device_role/find_test.rb | 8 +-- .../sync_device_type/create_test.rb | 2 +- .../sync_device/sync_device_type/find_test.rb | 8 +-- .../sync_manufacturer/create_test.rb | 2 +- .../sync_manufacturer/find_test.rb | 12 ++-- .../sync_device_type/update_test.rb | 2 +- .../sync_interfaces/create_test.rb | 6 +- .../sync_interfaces/delete_test.rb | 2 +- .../sync_device/sync_interfaces/find_test.rb | 8 +-- .../sync_ip_addresses/create_test.rb | 10 +-- .../sync_ip_addresses/delete_test.rb | 10 +-- .../sync_ip_addresses/find_test.rb | 6 +- .../sync_ip_addresses/update_test.rb | 8 +-- .../sync_interfaces/update_test.rb | 16 ++--- .../sync_device/sync_site/create_test.rb | 2 +- .../sync_device/sync_site/find_test.rb | 6 +- .../sync_device/sync_site/update_test.rb | 2 +- .../sync_host/sync_device/update_test.rb | 18 ++--- .../sync_host/sync_tenant/create_test.rb | 2 +- .../sync_host/sync_tenant/find_test.rb | 6 +- .../sync_host/sync_tenant/update_test.rb | 2 +- .../sync_virtual_machine/create_test.rb | 4 +- .../sync_cluster/create_test.rb | 2 +- .../sync_cluster/find_test.rb | 4 +- .../sync_cluster_type/find_test.rb | 8 +-- .../sync_cluster/update_test.rb | 2 +- .../sync_interfaces/create_test.rb | 6 +- .../sync_interfaces/delete_test.rb | 2 +- .../sync_interfaces/find_test.rb | 8 +-- .../sync_ip_addresses/create_test.rb | 10 +-- .../sync_ip_addresses/delete_test.rb | 10 +-- .../sync_ip_addresses/find_test.rb | 6 +- .../sync_ip_addresses/update_test.rb | 12 ++-- .../sync_interfaces/update_test.rb | 16 ++--- .../sync_virtual_machine/update_test.rb | 16 ++--- .../foreman_netbox/netbox_facet_test.rb | 2 +- test/models/foreman_netbox/nics/base_test.rb | 2 +- .../foreman_netbox/netbox_attributes_test.rb | 32 ++++----- .../netbox_parameters_comparator_test.rb | 62 ++++++++--------- 82 files changed, 432 insertions(+), 405 deletions(-) create mode 100644 .rubocop_todo.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4567ed7..5a2a68f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,24 +5,8 @@ env: DATABASE_URL: postgresql://postgres:@localhost/test DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: true jobs: - rubocop: - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - uses: actions/checkout@v2 - - name: Setup Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: 2.7 - - name: Setup - run: | - gem install bundler - bundle install --jobs=3 --retry=3 - - name: Run rubocop - run: bundle exec rubocop test: runs-on: ubuntu-latest - needs: rubocop timeout-minutes: 60 services: postgres: @@ -40,7 +24,7 @@ jobs: run: | sudo apt-get update sudo apt-get install -y build-essential libcurl4-openssl-dev libvirt-dev ruby-libvirt zlib1g-dev libpq-dev - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: repository: netbox-community/netbox-docker ref: 2.2.0 @@ -59,11 +43,11 @@ jobs: docker-compose pull docker-compose up -d sleep 180 - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: repository: theforeman/foreman ref: ${{ matrix.foreman-core-branch }} - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: path: foreman_netbox - name: Setup Ruby @@ -71,11 +55,11 @@ jobs: with: ruby-version: ${{ matrix.ruby-version }} - name: Setup Node - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - name: Cache node modules - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.npm key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} @@ -92,7 +76,7 @@ jobs: echo "gem 'foreman_netbox', path: './foreman_netbox'" > bundler.d/foreman_netbox.local.rb bundle lock --update - name: Cache gems - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: vendor/bundle key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} @@ -105,6 +89,9 @@ jobs: bundle exec rake db:migrate npm install bundle exec rake webpack:compile + - name: Run rubocop + run: bundle exec rake foreman_netbox:rubocop + if: ${{ matrix.foreman-core-branch == 'develop' }} - name: Run plugin tests run: | bundle exec rake test:foreman_netbox diff --git a/.rubocop.yml b/.rubocop.yml index 48b898e..7790e43 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,55 +1,24 @@ -require: rubocop-rails +inherit_from: .rubocop_todo.yml -AllCops: - TargetRubyVersion: 2.6 +inherit_gem: + theforeman-rubocop: + - default.yml -Rails: - Enabled: true - -# Don't enforce documentation -Style/Documentation: - Enabled: false - -# Force before_filter until upgrade to Rails 4 -Rails/ActionFilter: - EnforcedStyle: filter - -Metrics/ClassLength: +Layout/LineLength: Exclude: - 'test/**/*' -Metrics/MethodLength: - Max: 20 - -Metrics/LineLength: - Max: 200 - -Metrics/AbcSize: - Max: 31 - -Metrics/PerceivedComplexity: - Max: 10 - Metrics/BlockLength: Exclude: + - 'lib/foreman_gaffer_tape/engine.rb' - 'test/**/*' - 'lib/foreman_netbox/engine.rb' -Metrics/CyclomaticComplexity: - Max: 10 - -Style/Next: - Enabled: false - -# Support both ruby19 and hash_rockets -Style/HashSyntax: - Enabled: false - -Style/FormatStringToken: - EnforcedStyle: template - -Style/CaseLikeIf: - Enabled: false +Metrics/ClassLength: + Exclude: + - 'lib/foreman_gaffer_tape/engine.rb' + - 'test/**/*' -Gemspec/RequiredRubyVersion: - Enabled: false +Rails/DynamicFindBy: + Exclude: + - 'app/interactors/**/*' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..d9b8135 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,67 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-03-02 19:59:08 UTC using RuboCop version 1.23.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: + Exclude: + - 'foreman_netbox.gemspec' + +# Offense count: 10 +# Configuration parameters: IgnoredMethods, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 31 + +# Offense count: 3 +# Configuration parameters: IgnoredMethods. +Metrics/CyclomaticComplexity: + Max: 10 + +# Offense count: 13 +# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. +Metrics/MethodLength: + Max: 20 + +# Offense count: 2 +# Configuration parameters: IgnoredMethods. +Metrics/PerceivedComplexity: + Max: 10 + +# Offense count: 2 +# Configuration parameters: MinSize. +Performance/CollectionLiteralInLoop: + Exclude: + - 'test/services/foreman_netbox/netbox_parameters_comparator_test.rb' + +# Offense count: 4 +# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, IgnoredMethods. +# SupportedStyles: annotated, template, unannotated +Style/FormatStringToken: + EnforcedStyle: template + +# Offense count: 3 +# Cop supports --auto-correct. +Style/IfUnlessModifier: + Exclude: + - 'app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update.rb' + - 'app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update.rb' + - 'lib/tasks/foreman_netbox_tasks.rake' + +# Offense count: 2 +Style/MultilineBlockChain: + Exclude: + - 'app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete.rb' + - 'app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 149 diff --git a/app/interactors/foreman_netbox/delete_host/organizer.rb b/app/interactors/foreman_netbox/delete_host/organizer.rb index 532279b..47a4793 100644 --- a/app/interactors/foreman_netbox/delete_host/organizer.rb +++ b/app/interactors/foreman_netbox/delete_host/organizer.rb @@ -6,7 +6,7 @@ class Organizer include ::Interactor::Organizer organize DeleteHost::DeleteVirtualMachine, - DeleteHost::DeleteDevice + DeleteHost::DeleteDevice end end end diff --git a/app/interactors/foreman_netbox/sync_host/organizer.rb b/app/interactors/foreman_netbox/sync_host/organizer.rb index c438d18..3f91cee 100644 --- a/app/interactors/foreman_netbox/sync_host/organizer.rb +++ b/app/interactors/foreman_netbox/sync_host/organizer.rb @@ -11,7 +11,7 @@ class Organizer end organize SyncHost::SyncVirtualMachine::Organizer, - SyncHost::SyncDevice::Organizer + SyncHost::SyncDevice::Organizer def call super diff --git a/app/interactors/foreman_netbox/sync_host/sync_device/find.rb b/app/interactors/foreman_netbox/sync_host/sync_device/find.rb index 3033a1f..9f3add7 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_device/find.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_device/find.rb @@ -7,9 +7,7 @@ class Find include ::Interactor def call - # rubocop:disable Rails/DynamicFindBy context.device = find_by_serial || find_by_mac || find_by_name - # rubocop:enable Rails/DynamicFindBy rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}") context.fail!(error: "#{self.class}: #{e}") diff --git a/app/interactors/foreman_netbox/sync_host/sync_device/organizer.rb b/app/interactors/foreman_netbox/sync_host/sync_device/organizer.rb index 4250095..241a137 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_device/organizer.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_device/organizer.rb @@ -15,16 +15,16 @@ class Organizer end organize SyncDevice::Validate, - SyncHost::SyncTags::Organizer, - SyncHost::SyncTenant::Organizer, - SyncDevice::SyncSite::Organizer, - SyncDevice::SyncDeviceRole::Organizer, - SyncDevice::SyncDeviceType::Organizer, - SyncDevice::Find, - SyncDevice::Create, - SyncDevice::SyncInterfaces::Organizer, - SyncDevice::Update, - SyncDevice::SaveNetboxUrl + SyncHost::SyncTags::Organizer, + SyncHost::SyncTenant::Organizer, + SyncDevice::SyncSite::Organizer, + SyncDevice::SyncDeviceRole::Organizer, + SyncDevice::SyncDeviceType::Organizer, + SyncDevice::Find, + SyncDevice::Create, + SyncDevice::SyncInterfaces::Organizer, + SyncDevice::Update, + SyncDevice::SaveNetboxUrl end end end diff --git a/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/organizer.rb b/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/organizer.rb index 93b53c8..0ddf17b 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/organizer.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/organizer.rb @@ -12,7 +12,7 @@ class Organizer end organize SyncDeviceRole::Find, - SyncDeviceRole::Create + SyncDeviceRole::Create end end end diff --git a/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/organizer.rb b/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/organizer.rb index 9dca21b..e1c038b 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/organizer.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/organizer.rb @@ -12,9 +12,9 @@ class Organizer end organize SyncDeviceType::SyncManufacturer::Organizer, - SyncDeviceType::Find, - SyncDeviceType::Update, - SyncDeviceType::Create + SyncDeviceType::Find, + SyncDeviceType::Update, + SyncDeviceType::Create end end end diff --git a/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find.rb b/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find.rb index ff812a3..de01443 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find.rb @@ -9,10 +9,9 @@ class Find include ::Interactor def call - # rubocop:disable Rails/DynamicFindBy context.manufacturer = find_by_slug || find_by_name - # rubocop:enable Rails/DynamicFindBy - rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e + rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, + NetboxClientRuby::RemoteError => e ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}") context.fail!(error: "#{self.class}: #{e}") end diff --git a/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/organizer.rb b/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/organizer.rb index 6c644c7..c8592c3 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/organizer.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/organizer.rb @@ -13,7 +13,7 @@ class Organizer end organize SyncManufacturer::Find, - SyncManufacturer::Create + SyncManufacturer::Create end end end diff --git a/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find.rb b/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find.rb index 95c5df2..6367c08 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find.rb @@ -20,7 +20,7 @@ def call def params { - device_id: device.id + device_id: device.id, } end end diff --git a/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/organizer.rb b/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/organizer.rb index 0ace7b8..002bad5 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/organizer.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/organizer.rb @@ -12,10 +12,10 @@ class Organizer end organize SyncInterfaces::Find, - SyncInterfaces::Delete, - SyncInterfaces::Create, - SyncInterfaces::SyncIpAddresses::Organizer, - SyncInterfaces::Update + SyncInterfaces::Delete, + SyncInterfaces::Create, + SyncInterfaces::SyncIpAddresses::Organizer, + SyncInterfaces::Update end end end diff --git a/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete.rb b/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete.rb index 02b7a78..3f396bb 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete.rb @@ -21,7 +21,9 @@ def call ip_addresses_netbox_params = netbox_params.fetch(:ip_addresses, []) context.interfaces.each do |netbox_interface| - host_interface_ips = ip_addresses_netbox_params.select { |i| i.dig(:interface, :name) == netbox_interface.name } + host_interface_ips = ip_addresses_netbox_params.select do |i| + i.dig(:interface, :name) == netbox_interface.name + end .map { |i| i.fetch(:address) } context.ip_addresses diff --git a/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find.rb b/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find.rb index 770c678..0ce5525 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find.rb @@ -21,7 +21,7 @@ def call def params { - device_id: device.id + device_id: device.id, } end end diff --git a/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/organizer.rb b/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/organizer.rb index 9d00fab..251d5e1 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/organizer.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/organizer.rb @@ -13,9 +13,9 @@ class Organizer end organize SyncIpAddresses::Find, - SyncIpAddresses::Delete, - SyncIpAddresses::Update, - SyncIpAddresses::Create + SyncIpAddresses::Delete, + SyncIpAddresses::Update, + SyncIpAddresses::Create end end end diff --git a/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update.rb b/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update.rb index 28eb252..5b0dafd 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update.rb @@ -22,7 +22,9 @@ def update(netbox_interface) return unless new_params - netbox_interface.mac_address = new_params[:mac_address] if netbox_interface.mac_address != new_params[:mac_address] + if netbox_interface.mac_address != new_params[:mac_address] + netbox_interface.mac_address = new_params[:mac_address] + end assign_tags_to(netbox_interface) netbox_interface.save diff --git a/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/organizer.rb b/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/organizer.rb index 9c39d60..dafb2de 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/organizer.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/organizer.rb @@ -16,8 +16,8 @@ class Organizer end organize SyncSite::Find, - SyncSite::Update, - SyncSite::Create + SyncSite::Update, + SyncSite::Create end end end diff --git a/app/interactors/foreman_netbox/sync_host/sync_tags/organizer.rb b/app/interactors/foreman_netbox/sync_host/sync_tags/organizer.rb index e340e00..a62d92d 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_tags/organizer.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_tags/organizer.rb @@ -7,7 +7,7 @@ class Organizer include ::Interactor::Organizer DEFAULT_TAGS = [ - { name: 'foreman', slug: 'foreman' } + { name: 'foreman', slug: 'foreman' }, ].freeze after do @@ -15,7 +15,7 @@ class Organizer end organize SyncTags::Find, - SyncTags::Create + SyncTags::Create end end end diff --git a/app/interactors/foreman_netbox/sync_host/sync_tenant/organizer.rb b/app/interactors/foreman_netbox/sync_host/sync_tenant/organizer.rb index 75c4017..3c48bc9 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_tenant/organizer.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_tenant/organizer.rb @@ -11,8 +11,8 @@ class Organizer end organize SyncTenant::Find, - SyncTenant::Update, - SyncTenant::Create + SyncTenant::Update, + SyncTenant::Create end end end diff --git a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/find.rb b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/find.rb index eac0333..78e4d9e 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/find.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/find.rb @@ -7,9 +7,7 @@ class Find include ::Interactor def call - # rubocop:disable Rails/DynamicFindBy context.virtual_machine = find_by_mac || find_by_name - # rubocop:enable Rails/DynamicFindBy rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}") context.fail!(error: "#{self.class}: #{e}") diff --git a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/organizer.rb b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/organizer.rb index b3a0def..4188c1f 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/organizer.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/organizer.rb @@ -15,14 +15,14 @@ class Organizer end organize SyncVirtualMachine::Validate, - SyncHost::SyncTags::Organizer, - SyncHost::SyncTenant::Organizer, - SyncVirtualMachine::SyncCluster::Organizer, - SyncVirtualMachine::Find, - SyncVirtualMachine::Create, - SyncVirtualMachine::SyncInterfaces::Organizer, - SyncVirtualMachine::Update, - SyncVirtualMachine::SaveNetboxUrl + SyncHost::SyncTags::Organizer, + SyncHost::SyncTenant::Organizer, + SyncVirtualMachine::SyncCluster::Organizer, + SyncVirtualMachine::Find, + SyncVirtualMachine::Create, + SyncVirtualMachine::SyncInterfaces::Organizer, + SyncVirtualMachine::Update, + SyncVirtualMachine::SaveNetboxUrl end end end diff --git a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/organizer.rb b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/organizer.rb index 302d5ac..e20e589 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/organizer.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/organizer.rb @@ -12,9 +12,9 @@ class Organizer end organize SyncCluster::SyncClusterType::Organizer, - SyncCluster::Find, - SyncCluster::Update, - SyncCluster::Create + SyncCluster::Find, + SyncCluster::Update, + SyncCluster::Create end end end diff --git a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/organizer.rb b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/organizer.rb index 7e2ec88..f8f625d 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/organizer.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/organizer.rb @@ -13,7 +13,7 @@ class Organizer end organize SyncClusterType::Find, - SyncClusterType::Create + SyncClusterType::Create end end end diff --git a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find.rb b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find.rb index f18ffee..199647b 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find.rb @@ -20,7 +20,7 @@ def call def params { - virtual_machine_id: virtual_machine.id + virtual_machine_id: virtual_machine.id, } end end diff --git a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/organizer.rb b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/organizer.rb index daa810c..d8bbdd8 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/organizer.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/organizer.rb @@ -12,10 +12,10 @@ class Organizer end organize SyncInterfaces::Find, - SyncInterfaces::Delete, - SyncInterfaces::Create, - SyncInterfaces::SyncIpAddresses::Organizer, - SyncInterfaces::Update + SyncInterfaces::Delete, + SyncInterfaces::Create, + SyncInterfaces::SyncIpAddresses::Organizer, + SyncInterfaces::Update end end end diff --git a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete.rb b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete.rb index 3b7121b..e250f01 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete.rb @@ -21,7 +21,9 @@ def call ip_addresses_netbox_params = netbox_params.fetch(:ip_addresses, []) context.interfaces.each do |netbox_interface| - host_interface_ips = ip_addresses_netbox_params.select { |ip| ip.dig(:interface, :name) == netbox_interface.name } + host_interface_ips = ip_addresses_netbox_params.select do |ip| + ip.dig(:interface, :name) == netbox_interface.name + end .map { |ip| ip.fetch(:address) } context.ip_addresses diff --git a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find.rb b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find.rb index ca4dcca..cb93301 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find.rb @@ -17,7 +17,7 @@ def call def params { - virtual_machine_id: context.virtual_machine.id + virtual_machine_id: context.virtual_machine.id, } end end diff --git a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/organizer.rb b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/organizer.rb index cdd6ffd..88cb047 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/organizer.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/organizer.rb @@ -13,9 +13,9 @@ class Organizer end organize SyncIpAddresses::Find, - SyncIpAddresses::Delete, - SyncIpAddresses::Update, - SyncIpAddresses::Create + SyncIpAddresses::Delete, + SyncIpAddresses::Update, + SyncIpAddresses::Create end end end diff --git a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update.rb b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update.rb index 8a6e152..f3a8444 100644 --- a/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update.rb +++ b/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update.rb @@ -22,7 +22,9 @@ def update(netbox_interface) return unless new_params - netbox_interface.mac_address = new_params[:mac_address] if netbox_interface.mac_address != new_params[:mac_address] + if netbox_interface.mac_address != new_params[:mac_address] + netbox_interface.mac_address = new_params[:mac_address] + end assign_tags_to(netbox_interface) netbox_interface.save diff --git a/app/models/orchestration/netbox.rb b/app/models/orchestration/netbox.rb index eb433dc..1fed87e 100644 --- a/app/models/orchestration/netbox.rb +++ b/app/models/orchestration/netbox.rb @@ -23,8 +23,7 @@ def queue_netbox_push ::Foreman::Logging.logger('foreman_netbox/import') .info("Queued import of #{name} to Netbox. Changes that will be sent: #{netbox_params_diff}") - post_queue.create(name: _('Push host %s to Netbox') % self, priority: 100, - action: [self, :set_netbox]) + post_queue.create(name: _('Push host %s to Netbox') % self, priority: 100, action: [self, :set_netbox]) end def queue_netbox_destroy @@ -33,8 +32,7 @@ def queue_netbox_destroy ::Foreman::Logging.logger('foreman_netbox/import') .info("Queued delete of #{name} from Netbox.") - queue.create(name: _('Delete host %s from Netbox') % self, priority: 60, - action: [self, :del_netbox]) + queue.create(name: _('Delete host %s from Netbox') % self, priority: 60, action: [self, :del_netbox]) end def set_netbox diff --git a/app/services/foreman_netbox/cached_netbox_parameters.rb b/app/services/foreman_netbox/cached_netbox_parameters.rb index ec11c8d..6d0c55d 100644 --- a/app/services/foreman_netbox/cached_netbox_parameters.rb +++ b/app/services/foreman_netbox/cached_netbox_parameters.rb @@ -25,7 +25,7 @@ def call attr_accessor :result def read_interfaces - return unless data.keys.include?(:interfaces) + return unless data.key?(:interfaces) result[:interfaces] = data.fetch(:interfaces, {}).fetch(:results, []).map do |interface| interface.slice(:name, :mac_address) @@ -35,7 +35,7 @@ def read_interfaces end def read_ip_addresses - return unless data.keys.include?(:ip_addresses) + return unless data.key?(:ip_addresses) result[:ip_addresses] = data.fetch(:ip_addresses, {}).fetch(:results, []).map do |ip_address| ip_address.slice(:address) @@ -44,31 +44,31 @@ def read_ip_addresses end def read_virtual_machine - return unless data.keys.include?(:virtual_machine) + return unless data.key?(:virtual_machine) result[:virtual_machine] = data.fetch(:virtual_machine, {}).slice(:name, :vcpus, :memory, :disk) end def read_tenant - return unless data.keys.include?(:tenant) + return unless data.key?(:tenant) result[:tenant] = data.fetch(:tenant, {}).slice(:name, :slug) end def read_cluster - return unless data.keys.include?(:cluster) + return unless data.key?(:cluster) result[:cluster] = data.fetch(:cluster, {}).slice(:name) end def read_cluster_type - return unless data.keys.include?(:cluster_type) + return unless data.key?(:cluster_type) result[:cluster_type] = data.fetch(:cluster_type, {}).slice(:name, :slug) end def read_device - return unless data.keys.include?(:device) + return unless data.key?(:device) result[:device] = data.fetch(:device, {}) .slice(:name, :serial) @@ -77,25 +77,25 @@ def read_device end def read_device_role - return unless data.keys.include?(:device_role) + return unless data.key?(:device_role) result[:device_role] = data.fetch(:device_role, {}).slice(:name, :color, :slug) end def read_device_type - return unless data.keys.include?(:device_type) + return unless data.key?(:device_type) result[:device_type] = data.fetch(:device_type, {}).slice(:model, :slug) end def read_manufacturer - return unless data.keys.include?(:manufacturer) + return unless data.key?(:manufacturer) result[:manufacturer] = data.fetch(:manufacturer, {}).slice(:name, :slug) end def read_site - return unless data.keys.include?(:site) + return unless data.key?(:site) result[:site] = data.fetch(:site, {}).slice(:name, :slug) end diff --git a/app/services/foreman_netbox/netbox_parameters.rb b/app/services/foreman_netbox/netbox_parameters.rb index d40398b..477076c 100644 --- a/app/services/foreman_netbox/netbox_parameters.rb +++ b/app/services/foreman_netbox/netbox_parameters.rb @@ -6,15 +6,15 @@ class NetboxParameters UNKNOWN = 'Unknown' DEFAULT_INTERFACE_TYPE = 'virtual' CLUSTER_TYPES = { - :'Foreman::Model::Vmware' => { + 'Foreman::Model::Vmware': { name: 'VMware ESXi', - slug: 'vmware-esxi' - } + slug: 'vmware-esxi', + }, }.freeze DEVICE_ROLE = { name: 'SERVER', color: '9e9e9e', - slug: 'server' + slug: 'server', }.freeze def self.call(host) @@ -46,7 +46,7 @@ def netbox_compute_attributes vcpus: compute_object&.cpus, memory: compute_object&.memory_mb, disk: compute_object&.volumes&.map(&:size_gb)&.reduce(&:+), - cluster: compute_object&.cluster + cluster: compute_object&.cluster, }.compact end end @@ -55,8 +55,8 @@ def tenant { tenant: { name: host.owner&.netbox_tenant_name, - slug: host.owner&.netbox_tenant_slug - } + slug: host.owner&.netbox_tenant_slug, + }, } end @@ -64,14 +64,14 @@ def device { device: { name: host.name, - serial: host.facts.deep_symbolize_keys[:serialnumber] - } + serial: host.facts.deep_symbolize_keys[:serialnumber], + }, } end def device_role { - device_role: DEVICE_ROLE + device_role: DEVICE_ROLE, } end @@ -81,8 +81,8 @@ def device_type { device_type: { model: model, - slug: model.parameterize - } + slug: model.parameterize, + }, } end @@ -92,8 +92,8 @@ def manufacturer { manufacturer: { name: name, - slug: cached_netbox_params.dig(:manufacturer, :slug) || name.parameterize - } + slug: cached_netbox_params.dig(:manufacturer, :slug) || name.parameterize, + }, } end @@ -101,8 +101,8 @@ def site { site: { name: host.location&.netbox_site_name, - slug: host.location&.netbox_site_slug - } + slug: host.location&.netbox_site_slug, + }, } end @@ -116,10 +116,10 @@ def interfaces name: identifier || (mac_address && "Interface #{mac_address}"), mac_address: mac_address, type: { - value: DEFAULT_INTERFACE_TYPE - } + value: DEFAULT_INTERFACE_TYPE, + }, } - end + end, } end @@ -129,7 +129,7 @@ def ip_addresses ip_addresses: host.interfaces.map do |interface| [ interface.ip && interface.subnet && "#{interface.ip}/#{interface.subnet.cidr}", - interface.ip6 && interface.subnet6 && "#{interface.ip6}/#{interface.subnet6.cidr}" + interface.ip6 && interface.subnet6 && "#{interface.ip6}/#{interface.subnet6.cidr}", ].compact.map do |ip_address| identifier = interface.identifier.present? && interface.identifier mac_address = interface.mac&.upcase @@ -137,11 +137,11 @@ def ip_addresses { address: ip_address, interface: { - name: identifier || (mac_address && "Interface #{mac_address}") - } + name: identifier || (mac_address && "Interface #{mac_address}"), + }, } end - end.flatten + end.flatten, } end # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity @@ -152,15 +152,15 @@ def virtual_machine :vcpus, :memory, :disk ).merge( name: host.name - ) + ), } end def cluster { cluster: { - name: netbox_compute_attributes[:cluster] - }.compact + name: netbox_compute_attributes[:cluster], + }.compact, } end @@ -168,7 +168,7 @@ def cluster_type type = host.compute_resource&.type&.to_sym { - cluster_type: CLUSTER_TYPES.fetch(type, nil) + cluster_type: CLUSTER_TYPES.fetch(type, nil), } end end diff --git a/app/services/foreman_netbox/netbox_parameters_comparator.rb b/app/services/foreman_netbox/netbox_parameters_comparator.rb index 0457e37..0b60aeb 100644 --- a/app/services/foreman_netbox/netbox_parameters_comparator.rb +++ b/app/services/foreman_netbox/netbox_parameters_comparator.rb @@ -32,22 +32,27 @@ def removed_keys def keys_diff result = {} - result[:added] = added_keys.each_with_object({}) { |key, memo| memo[key] = new_hash[key] } if added_keys.any? - result[:removed] = removed_keys.each_with_object({}) { |key, memo| memo[key] = old_hash[key] } if removed_keys.any? + result[:added] = added_keys.index_with { |key| new_hash[key] } if added_keys.any? + if removed_keys.any? + result[:removed] = removed_keys.index_with do |key| + old_hash[key] + end + end result end def diff_old old_hash.except(*removed_keys).each_with_object({}) do |(key, old_value), memo| - if old_value.is_a?(Hash) + case old_value + when Hash new_value = new_hash.fetch(key, {}) diff = ForemanNetbox::NetboxParametersComparator.call(old_value, new_value) next unless diff.keys.any? memo[key] = diff - elsif old_value.is_a?(Array) + when Array next if new_hash[key] memo[key] = { added: [], removed: old_value } @@ -64,7 +69,8 @@ def diff_old # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity def diff_new new_hash.except(*added_keys).each_with_object({}) do |(key, new_value), memo| - if new_value.is_a?(Hash) + case new_value + when Hash old_value = old_hash.fetch(key, {}) next if old_value == new_value @@ -74,7 +80,7 @@ def diff_new next unless diff.keys.any? memo[key] = diff - elsif new_value.is_a?(Array) + when Array old_value = old_hash.fetch(key, []) added = new_value.reject { |item| old_value.find { |x| x == item } } removed = old_value.reject { |item| new_value.find { |x| x == item } } diff --git a/foreman_netbox.gemspec b/foreman_netbox.gemspec index 22750cd..cb04ce6 100644 --- a/foreman_netbox.gemspec +++ b/foreman_netbox.gemspec @@ -24,6 +24,5 @@ Gem::Specification.new do |s| s.add_dependency 'netbox-client-ruby', '>= 0.5.5', '< 0.8.0' s.add_development_dependency 'rdoc' - s.add_development_dependency 'rubocop', '~> 1.45.1' - s.add_development_dependency 'rubocop-rails', '~> 2.9.1' + s.add_development_dependency 'theforeman-rubocop', '~> 0.1.2' end diff --git a/lib/foreman_netbox/engine.rb b/lib/foreman_netbox/engine.rb index 77c661a..1fe7740 100644 --- a/lib/foreman_netbox/engine.rb +++ b/lib/foreman_netbox/engine.rb @@ -17,7 +17,7 @@ class Engine < ::Rails::Engine end end - initializer 'foreman_netbox.register_plugin', :before => :finisher_hook do |_app| + initializer 'foreman_netbox.register_plugin', before: :finisher_hook do |_app| Foreman::Plugin.register :foreman_netbox do requires_foreman '>= 3.1' @@ -29,33 +29,33 @@ class Engine < ::Rails::Engine # extend host show page extend_page('hosts/show') do |context| context.add_pagelet :main_tabs, - name: N_('Netbox'), - partial: 'hosts/netbox_tab', - onlyif: proc { |host| host.netbox_facet.synchronized_at } + name: N_('Netbox'), + partial: 'hosts/netbox_tab', + onlyif: proc { |host| host.netbox_facet.synchronized_at } end settings do category(:netbox, N_('Netbox')) do setting 'netbox_url', - type: :string, - default: '-', - full_name: N_('Netbox URL'), - description: N_('URL where Netbox is reachable') + type: :string, + default: '-', + full_name: N_('Netbox URL'), + description: N_('URL where Netbox is reachable') setting 'netbox_api_token', - type: :string, - default: '-', - full_name: N_('Netbox API token'), - description: N_('API token to Netbox') + type: :string, + default: '-', + full_name: N_('Netbox API token'), + description: N_('API token to Netbox') setting 'netbox_orchestration_enabled', - type: :boolean, - default: false, - full_name: N_('Netbox Orchestration'), - description: N_('Enable Netbox Orchestration') + type: :boolean, + default: false, + full_name: N_('Netbox Orchestration'), + description: N_('Enable Netbox Orchestration') setting 'netbox_skip_site_update', - type: :boolean, - default: false, - full_name: N_('Skip Site Update'), - description: N_('Skip updating Site attribute for Devices') + type: :boolean, + default: false, + full_name: N_('Skip Site Update'), + description: N_('Skip updating Site attribute for Devices') end end diff --git a/lib/tasks/foreman_netbox_tasks.rake b/lib/tasks/foreman_netbox_tasks.rake index 5b9393e..6b6221c 100644 --- a/lib/tasks/foreman_netbox_tasks.rake +++ b/lib/tasks/foreman_netbox_tasks.rake @@ -60,8 +60,6 @@ Rake::Task[:test].enhance ['test:foreman_netbox'] load 'tasks/jenkins.rake' -# rubocop:disable Style/IfUnlessModifier if Rake::Task.task_defined?(:'jenkins:unit') Rake::Task['jenkins:unit'].enhance ['test:foreman_netbox', 'foreman_netbox:rubocop'] end -# rubocop:enable Style/IfUnlessModifier diff --git a/test/integration/foreman_netbox/sync_k8s_physical_host_test.rb b/test/integration/foreman_netbox/sync_k8s_physical_host_test.rb index 9b0eebd..53cf267 100644 --- a/test/integration/foreman_netbox/sync_k8s_physical_host_test.rb +++ b/test/integration/foreman_netbox/sync_k8s_physical_host_test.rb @@ -32,7 +32,7 @@ class SyncK8sPhysicalHostTest < ActiveSupport::TestCase mac: '45:E9:6A:83:02:20', ip6: '1600:0:2d0:202::17', subnet6: FactoryBot.build_stubbed(:subnet_ipv6, organizations: [], locations: []) - ) + ), ] ).tap do |host| host.stubs(:ip).returns(host.interfaces.find(&:ip).ip) @@ -71,15 +71,15 @@ class SyncK8sPhysicalHostTest < ActiveSupport::TestCase end expected_tag_ids = subject.tags.pluck('id') - assert (expected_tag_ids - subject.device.tags.pluck('id')).empty? - assert (expected_tag_ids - subject.device_type.tags.pluck('id')).empty? - assert (expected_tag_ids - subject.site.tags.pluck('id')).empty? - assert (expected_tag_ids - subject.tenant.tags.pluck('id')).empty? + assert_empty(expected_tag_ids - subject.device.tags.pluck('id')) + assert_empty(expected_tag_ids - subject.device_type.tags.pluck('id')) + assert_empty(expected_tag_ids - subject.site.tags.pluck('id')) + assert_empty(expected_tag_ids - subject.tenant.tags.pluck('id')) subject.interfaces.reload.each do |interface| - assert (expected_tag_ids - interface.tags.pluck('id')).empty? + assert_empty(expected_tag_ids - interface.tags.pluck('id')) end subject.ip_addresses.reload.each do |interface| - assert (expected_tag_ids - interface.tags.pluck('id')).empty? + assert_empty(expected_tag_ids - interface.tags.pluck('id')) end end end diff --git a/test/integration/foreman_netbox/sync_rhel_physical_host_test.rb b/test/integration/foreman_netbox/sync_rhel_physical_host_test.rb index 9580528..ec290eb 100644 --- a/test/integration/foreman_netbox/sync_rhel_physical_host_test.rb +++ b/test/integration/foreman_netbox/sync_rhel_physical_host_test.rb @@ -32,7 +32,7 @@ class SyncRhelPhysicalHostTest < ActiveSupport::TestCase mac: '45:E9:6A:83:02:21', ip6: '1600:0:2d0:202::18', subnet6: FactoryBot.build_stubbed(:subnet_ipv6, organizations: [], locations: []) - ) + ), ] ).tap do |host| host.stubs(:ip).returns(host.interfaces.find(&:ip).ip) @@ -71,15 +71,15 @@ class SyncRhelPhysicalHostTest < ActiveSupport::TestCase end expected_tag_ids = subject.tags.pluck('id') - assert (expected_tag_ids - subject.device.tags.pluck('id')).empty? - assert (expected_tag_ids - subject.device_type.tags.pluck('id')).empty? - assert (expected_tag_ids - subject.site.tags.pluck('id')).empty? - assert (expected_tag_ids - subject.tenant.tags.pluck('id')).empty? + assert_empty(expected_tag_ids - subject.device.tags.pluck('id')) + assert_empty(expected_tag_ids - subject.device_type.tags.pluck('id')) + assert_empty(expected_tag_ids - subject.site.tags.pluck('id')) + assert_empty(expected_tag_ids - subject.tenant.tags.pluck('id')) subject.interfaces.reload.each do |interface| - assert (expected_tag_ids - interface.tags.pluck('id')).empty? + assert_empty(expected_tag_ids - interface.tags.pluck('id')) end subject.ip_addresses.reload.each do |interface| - assert (expected_tag_ids - interface.tags.pluck('id')).empty? + assert_empty(expected_tag_ids - interface.tags.pluck('id')) end end end diff --git a/test/integration/foreman_netbox/sync_rhel_virtual_host_test.rb b/test/integration/foreman_netbox/sync_rhel_virtual_host_test.rb index 73d82da..302f2db 100644 --- a/test/integration/foreman_netbox/sync_rhel_virtual_host_test.rb +++ b/test/integration/foreman_netbox/sync_rhel_virtual_host_test.rb @@ -31,7 +31,7 @@ class SyncRhelVirtualHostTest < ActiveSupport::TestCase mac: '45:E9:6A:83:02:22', ip6: '1600:0:2d0:202::19', subnet6: FactoryBot.build_stubbed(:subnet_ipv6, organizations: [], locations: []) - ) + ), ] ).tap do |host| host.stubs(:ip).returns(host.interfaces.find(&:ip).ip) @@ -46,7 +46,7 @@ class SyncRhelVirtualHostTest < ActiveSupport::TestCase cpus: 1, memory_mb: 1024, volumes: [ - OpenStruct.new(size_gb: 120) + OpenStruct.new(size_gb: 120), ] ) ) @@ -84,14 +84,14 @@ class SyncRhelVirtualHostTest < ActiveSupport::TestCase end expected_tag_ids = subject.tags.pluck('id') - assert (expected_tag_ids - subject.virtual_machine.tags.pluck('id')).empty? - assert (expected_tag_ids - subject.tenant.tags.pluck('id')).empty? - assert (expected_tag_ids - subject.cluster.tags.pluck('id')).empty? + assert_empty(expected_tag_ids - subject.virtual_machine.tags.pluck('id')) + assert_empty(expected_tag_ids - subject.tenant.tags.pluck('id')) + assert_empty(expected_tag_ids - subject.cluster.tags.pluck('id')) subject.interfaces.reload.each do |interface| - assert (expected_tag_ids - interface.tags.pluck('id')).empty? + assert_empty(expected_tag_ids - interface.tags.pluck('id')) end subject.ip_addresses.reload.each do |interface| - assert (expected_tag_ids - interface.tags.pluck('id')).empty? + assert_empty(expected_tag_ids - interface.tags.pluck('id')) end end end diff --git a/test/interactors/foreman_netbox/sync_host/organizer_test.rb b/test/interactors/foreman_netbox/sync_host/organizer_test.rb index 7f39776..a719c67 100644 --- a/test/interactors/foreman_netbox/sync_host/organizer_test.rb +++ b/test/interactors/foreman_netbox/sync_host/organizer_test.rb @@ -20,7 +20,7 @@ class SyncHostOrganizerTest < ActiveSupport::TestCase # rubocop:disable Layout/FirstArrayElementIndentation default_tags.each do |tag| stub_get_netbox_request("extras/tags.json?limit=50&slug=#{tag.slug}", results: [ - { id: tag.id, name: tag.name, slug: tag.slug } + { id: tag.id, name: tag.name, slug: tag.slug }, ]) stub_request(:get, "#{Setting[:netbox_url]}/api/extras/tags/#{tag.id}.json") .to_return( @@ -28,27 +28,27 @@ class SyncHostOrganizerTest < ActiveSupport::TestCase body: { id: tag.id, name: tag.name, - slug: tag.slug + slug: tag.slug, }.to_json ) end stub_get_netbox_request('tenancy/tenants.json?limit=50&slug=admin-user', results: [ - { id: 1, name: host.owner.name, slug: host.owner.name.parameterize, tags: tags } + { id: 1, name: host.owner.name, slug: host.owner.name.parameterize, tags: tags }, ]) stub_get_netbox_request('dcim/sites.json?limit=50&slug=location-1', results: [ - { id: 1, name: host.location.netbox_site_name, slug: host.location.netbox_site_slug, tags: tags } + { id: 1, name: host.location.netbox_site_name, slug: host.location.netbox_site_slug, tags: tags }, ]) stub_get_netbox_request('dcim/device-roles.json?limit=50&slug=server', results: [ - { id: 1, name: 'Device Role', slug: 'server' } + { id: 1, name: 'Device Role', slug: 'server' }, ]) stub_get_netbox_request('dcim/manufacturers.json?limit=50&slug=unknown', results: [ - { id: 1, name: 'Unknown', slug: 'unknown' } + { id: 1, name: 'Unknown', slug: 'unknown' }, ]) stub_get_netbox_request('dcim/device-types.json?limit=50&slug=unknown', results: [ - { id: 1, name: 'Unknown', slug: 'unknown', tags: tags } + { id: 1, name: 'Unknown', slug: 'unknown', tags: tags }, ]) stub_get_netbox_request("dcim/devices.json?limit=50&serial=#{host.facts[:serialnumber]}", results: [ - { id: 1, name: host.name, serial: host.facts[:serialnumber], tags: tags } + { id: 1, name: host.name, serial: host.facts[:serialnumber], tags: tags }, ]) stub_get_netbox_request('dcim/interfaces.json?device_id=1&limit=50', results: []) stub_get_netbox_request('ipam/ip-addresses.json?device_id=1&limit=50', results: []) @@ -87,7 +87,7 @@ def stub_get_netbox_request(path, results:) status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 1, - results: results + results: results, }.to_json ) end diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/create_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/create_test.rb index 3b1be34..7d40f23 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/create_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/create_test.rb @@ -45,7 +45,7 @@ class CreateDeviceTest < ActiveSupport::TestCase device_role: device_role.id, site: site.id, tenant: tenant.id, - tags: tags.map(&:id) + tags: tags.map(&:id), }.to_json ).to_return( status: 201, headers: { 'Content-Type': 'application/json' }, diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/create_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/create_test.rb index e3c1473..17381cd 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/create_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/create_test.rb @@ -23,7 +23,7 @@ class CreateDeviceRoleTest < ActiveSupport::TestCase body: { name: device_role_params[:name], color: device_role_params[:color], - slug: device_role_params[:slug] + slug: device_role_params[:slug], }.to_json ).to_return( status: 201, headers: { 'Content-Type': 'application/json' }, diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/find_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/find_test.rb index a3ae51c..c338834 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/find_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/find_test.rb @@ -28,9 +28,9 @@ class FindDeviceRoleTest < ActiveSupport::TestCase { id: 1, name: device_role_params[:name], - slug: device_role_params[:slug] - } - ] + slug: device_role_params[:slug], + }, + ], }.to_json ) @@ -47,7 +47,7 @@ class FindDeviceRoleTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 0, - results: [] + results: [], }.to_json ) diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/create_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/create_test.rb index fc4bd1c..0d077e5 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/create_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/create_test.rb @@ -34,7 +34,7 @@ class CreateDeviceTypeTest < ActiveSupport::TestCase model: host.netbox_facet.netbox_params.dig(:device_type, :model), slug: host.netbox_facet.netbox_params.dig(:device_type, :slug), manufacturer: manufacturer.id, - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 201, headers: { 'Content-Type': 'application/json' }, diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/find_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/find_test.rb index 740a5c9..ae8efb0 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/find_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/find_test.rb @@ -33,9 +33,9 @@ class FindDeviceTypeTest < ActiveSupport::TestCase { id: 1, name: host.facts.symbolize_keys.fetch(:'dmi::product::name'), - slug: slug - } - ] + slug: slug, + }, + ], }.to_json ) @@ -52,7 +52,7 @@ class FindDeviceTypeTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 0, - results: [] + results: [], }.to_json ) diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/create_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/create_test.rb index f205b52..12f2ab3 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/create_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/create_test.rb @@ -26,7 +26,7 @@ class CreateManufacturerTest < ActiveSupport::TestCase stub_post = stub_request(:post, "#{Setting[:netbox_url]}/api/dcim/manufacturers/").with( body: { name: host.netbox_facet.netbox_params.dig(:manufacturer, :name), - slug: host.netbox_facet.netbox_params.dig(:manufacturer, :slug) + slug: host.netbox_facet.netbox_params.dig(:manufacturer, :slug), }.to_json ).to_return( status: 201, headers: { 'Content-Type': 'application/json' }, diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find_test.rb index f9196ed..85edbb1 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find_test.rb @@ -14,7 +14,7 @@ class FindManufacturerTest < ActiveSupport::TestCase host.stubs(:facts).returns( { 'dmi::manufacturer' => 'Manufacturer', - 'dmi::product::name' => 'device type 2' + 'dmi::product::name' => 'device type 2', } ) end @@ -34,7 +34,7 @@ class FindManufacturerTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 1, - results: [netbox_params.fetch(:manufacturer).merge(id: 1)] + results: [netbox_params.fetch(:manufacturer).merge(id: 1)], }.to_json ) stub_get_with_name = stub_request(:get, "#{Setting[:netbox_url]}/api/dcim/manufacturers.json").with( @@ -55,7 +55,7 @@ class FindManufacturerTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 0, - results: [] + results: [], }.to_json ) stub_get_with_name = stub_request(:get, "#{Setting[:netbox_url]}/api/dcim/manufacturers.json").with( @@ -64,7 +64,7 @@ class FindManufacturerTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 1, - results: [netbox_params.fetch(:manufacturer).merge(id: 1)] + results: [netbox_params.fetch(:manufacturer).merge(id: 1)], }.to_json ) @@ -83,7 +83,7 @@ class FindManufacturerTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 0, - results: [] + results: [], }.to_json ) @@ -93,7 +93,7 @@ class FindManufacturerTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 0, - results: [] + results: [], }.to_json ) diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/update_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/update_test.rb index 738d784..db5a36f 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/update_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/update_test.rb @@ -32,7 +32,7 @@ class UpdateDeviceTypeTest < ActiveSupport::TestCase it 'updates device type' do stub_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/dcim/device-types/1.json").with( body: { - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 200, headers: { 'Content-Type': 'application/json' }, diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/create_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/create_test.rb index fde8eae..a5f5c79 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/create_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/create_test.rb @@ -21,7 +21,7 @@ class CreateDeviceInterfacesTest < ActiveSupport::TestCase interfaces: [ FactoryBot.build_stubbed(:nic_base, mac: 'FE:13:C6:44:29:24', ip: '10.0.0.1', ip6: '1500:0:2d0:201::1'), FactoryBot.build_stubbed(:nic_base, mac: 'FE:13:C6:44:29:22', ip: '10.0.0.2', ip6: '1500:0:2d0:201::2'), - FactoryBot.build_stubbed(:nic_base, identifier: nil, mac: nil) + FactoryBot.build_stubbed(:nic_base, identifier: nil, mac: nil), ] ) end @@ -39,13 +39,13 @@ class CreateDeviceInterfacesTest < ActiveSupport::TestCase mac_address: host.interfaces.first.mac.upcase, type: ForemanNetbox::NetboxParameters::DEFAULT_INTERFACE_TYPE, device: device.id, - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 201, headers: { 'Content-Type': 'application/json' }, body: { id: 1, - name: host.interfaces.first.netbox_name + name: host.interfaces.first.netbox_name, }.to_json ) diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/delete_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/delete_test.rb index f483ce8..b974ca6 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/delete_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/delete_test.rb @@ -25,7 +25,7 @@ class DeleteDeviceInterfacesTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 1, - results: [{ id: interface_id, name: 'eth0' }] + results: [{ id: interface_id, name: 'eth0' }], }.to_json ) end diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find_test.rb index 30032e0..64f9411 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find_test.rb @@ -24,8 +24,8 @@ class FindDeviceInterfacesTest < ActiveSupport::TestCase body: { count: 1, results: [ - { id: 1 } - ] + { id: 1 }, + ], }.to_json ) @@ -42,11 +42,11 @@ class FindDeviceInterfacesTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 0, - results: [] + results: [], }.to_json ) - assert_equal [], subject.interfaces.map(&:id) + assert_empty subject.interfaces.map(&:id) assert_requested(stub_get) end end diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/create_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/create_test.rb index b598b1a..d32001f 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/create_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/create_test.rb @@ -26,7 +26,7 @@ class CreateDeviceIpAddressesTest < ActiveSupport::TestCase ip6: '1500:0:2d0:201::1', subnet: subnet, subnet6: subnet6 - ) + ), ] ) end @@ -39,7 +39,7 @@ class CreateDeviceIpAddressesTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 0, - results: [] + results: [], }.to_json ) stub_request(:get, "#{Setting[:netbox_url]}/api/ipam/ip-addresses.json").with( @@ -48,7 +48,7 @@ class CreateDeviceIpAddressesTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 1, - results: [{ id: 2 }] + results: [{ id: 2 }], }.to_json ) end @@ -59,7 +59,7 @@ class CreateDeviceIpAddressesTest < ActiveSupport::TestCase address: host.interfaces.first.netbox_ip, assigned_object_type: 'dcim.interface', assigned_object_id: interfaces.first.id, - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 201, headers: { 'Content-Type': 'application/json' }, @@ -71,7 +71,7 @@ class CreateDeviceIpAddressesTest < ActiveSupport::TestCase address: host.interfaces.first.netbox_ip6, assigned_object_type: 'dcim.interface', assigned_object_id: interfaces.first.id, - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 201, headers: { 'Content-Type': 'application/json' }, diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete_test.rb index 9899120..492740d 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete_test.rb @@ -19,7 +19,7 @@ class DeleteDeviceIpAddressesTest < ActiveSupport::TestCase :nic_base, ip: '10.0.0.1', subnet: FactoryBot.build_stubbed(:subnet_ipv4) - ) + ), ] ) end @@ -39,8 +39,8 @@ class DeleteDeviceIpAddressesTest < ActiveSupport::TestCase body: { count: 1, results: [ - { id: interface_id, name: host.interfaces.first.netbox_name } - ] + { id: interface_id, name: host.interfaces.first.netbox_name }, + ], }.to_json ) stub_request(:get, "#{Setting[:netbox_url]}/api/ipam/ip-addresses.json").with( @@ -51,8 +51,8 @@ class DeleteDeviceIpAddressesTest < ActiveSupport::TestCase count: 2, results: [ { id: ip_addresses_v4_id, address: ip_addresses_v4, assigned_object_type: 'dcim.interface', assigned_object_id: interface_id }, - { id: ip_addresses_v6_id, address: ip_addresses_v6, assigned_object_type: 'dcim.interface', assigned_object_id: interface_id } - ] + { id: ip_addresses_v6_id, address: ip_addresses_v6, assigned_object_type: 'dcim.interface', assigned_object_id: interface_id }, + ], }.to_json ) end diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find_test.rb index 1c17406..7aa1dcc 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find_test.rb @@ -23,7 +23,7 @@ class FindDeviceIpAddressesTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 1, - results: [{ id: 1 }] + results: [{ id: 1 }], }.to_json ) @@ -40,11 +40,11 @@ class FindDeviceIpAddressesTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 0, - results: [] + results: [], }.to_json ) - assert_equal [], subject.ip_addresses.map(&:id) + assert_empty subject.ip_addresses.map(&:id) assert_requested(stub_get) end end diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/update_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/update_test.rb index 6acad3b..757c40b 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/update_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/update_test.rb @@ -16,7 +16,7 @@ class UpdateDeviceIpAddressesTest < ActiveSupport::TestCase let(:ip_addresses_data) do [ { id: 1, address: host.netbox_facet.netbox_params[:ip_addresses].first[:address], tags: tags_data }, - { id: 2, address: host.netbox_facet.netbox_params[:ip_addresses].second[:address], tags: [] } + { id: 2, address: host.netbox_facet.netbox_params[:ip_addresses].second[:address], tags: [] }, ] end let(:host) do @@ -30,7 +30,7 @@ class UpdateDeviceIpAddressesTest < ActiveSupport::TestCase ip6: '1600:0:2d0:202::17', subnet: FactoryBot.build_stubbed(:subnet_ipv4, organizations: [], locations: []), subnet6: FactoryBot.build_stubbed(:subnet_ipv6, organizations: [], locations: []) - ) + ), ] ) end @@ -43,7 +43,7 @@ class UpdateDeviceIpAddressesTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: ip_addresses_data.count, - results: ip_addresses_data + results: ip_addresses_data, }.to_json ) end @@ -52,7 +52,7 @@ class UpdateDeviceIpAddressesTest < ActiveSupport::TestCase stub_unexpected_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/ipam/ip-addresses/#{ip_addresses_data.first[:id]}.json") stub_expected_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/ipam/ip-addresses/#{ip_addresses_data.second[:id]}.json").with( body: { - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 200, headers: { 'Content-Type': 'application/json' }, diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update_test.rb index c06433e..6186804 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update_test.rb @@ -23,7 +23,7 @@ class UpdateDeviceInterfacesTest < ActiveSupport::TestCase :nic_base, identifier: 'eth1', mac: old_mac - ) + ), ] ) end @@ -47,15 +47,15 @@ class UpdateDeviceInterfacesTest < ActiveSupport::TestCase id: 1, name: host.interfaces.first.netbox_name, mac_address: new_mac.upcase, - tags: [] - } - ] + tags: [], + }, + ], }.to_json ) stub_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/dcim/interfaces/1.json").with( body: { mac_address: host.interfaces.first.mac.upcase, - tags: tags.map(&:id) + tags: tags.map(&:id), }.to_json ).to_return( status: 200, headers: { 'Content-Type': 'application/json' }, @@ -81,9 +81,9 @@ class UpdateDeviceInterfacesTest < ActiveSupport::TestCase id: 1, name: host.interfaces.first.netbox_name, mac_address: old_mac, - tags: tags.map { |t| { id: t.id, name: t.name, slug: t.slug } } - } - ] + tags: tags.map { |t| { id: t.id, name: t.name, slug: t.slug } }, + }, + ], }.to_json ) diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/create_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/create_test.rb index e655134..76fd8fe 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/create_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/create_test.rb @@ -29,7 +29,7 @@ class CreateSiteTest < ActiveSupport::TestCase body: { name: host.location.netbox_site_name, slug: host.location.netbox_site_slug, - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 201, headers: { 'Content-Type': 'application/json' }, diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/find_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/find_test.rb index c4ead33..8b297b3 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/find_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/find_test.rb @@ -30,8 +30,8 @@ class FindSiteTest < ActiveSupport::TestCase body: { count: 1, results: [ - { id: 1, name: host.location.netbox_site_name, slug: host.location.netbox_site_slug } - ] + { id: 1, name: host.location.netbox_site_name, slug: host.location.netbox_site_slug }, + ], }.to_json ) @@ -48,7 +48,7 @@ class FindSiteTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 0, - results: [] + results: [], }.to_json ) diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/update_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/update_test.rb index cdc582d..4159420 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/update_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/update_test.rb @@ -30,7 +30,7 @@ class UpdateSiteTest < ActiveSupport::TestCase it 'updates site' do stub_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/dcim/sites/1.json").with( body: { - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 200, headers: { 'Content-Type': 'application/json' }, diff --git a/test/interactors/foreman_netbox/sync_host/sync_device/update_test.rb b/test/interactors/foreman_netbox/sync_host/sync_device/update_test.rb index ed3efd6..e9e0d0c 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_device/update_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_device/update_test.rb @@ -32,14 +32,14 @@ class UpdateDeviceTest < ActiveSupport::TestCase 'primary_ip4' => { 'id' => 1, 'family' => 4, - 'address' => '10.0.0.8/24' + 'address' => '10.0.0.8/24', }, 'primary_ip6' => { 'id' => 2, 'family' => 6, - 'address' => '1600:0:2d0:202::18/64' + 'address' => '1600:0:2d0:202::18/64', }, - 'tags' => device_tags + 'tags' => device_tags, } ) end @@ -90,8 +90,8 @@ class UpdateDeviceTest < ActiveSupport::TestCase count: 2, results: [ { id: primary_ip4.id, address: primary_ip4.address.address }, - { id: primary_ip6.id, address: primary_ip6.address.address } - ] + { id: primary_ip6.id, address: primary_ip6.address.address }, + ], }.to_json ) end @@ -109,7 +109,7 @@ class UpdateDeviceTest < ActiveSupport::TestCase body: { id: t['id'], name: t['name'], - slug: t['slug'] + slug: t['slug'], }.to_json ) end @@ -163,7 +163,7 @@ class UpdateDeviceTest < ActiveSupport::TestCase site: site.id, tenant: tenant.id, serial: serialnumber, - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 200, headers: { 'Content-Type': 'application/json' }, @@ -187,7 +187,7 @@ class UpdateDeviceTest < ActiveSupport::TestCase primary_ip6: primary_ip6.id, site: site.id, tenant: tenant.id, - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 200, headers: { 'Content-Type': 'application/json' }, @@ -219,7 +219,7 @@ class UpdateDeviceTest < ActiveSupport::TestCase body: { id: t['id'], name: t['name'], - slug: t['slug'] + slug: t['slug'], }.to_json ) end diff --git a/test/interactors/foreman_netbox/sync_host/sync_tenant/create_test.rb b/test/interactors/foreman_netbox/sync_host/sync_tenant/create_test.rb index 9a2ca24..90e4951 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_tenant/create_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_tenant/create_test.rb @@ -28,7 +28,7 @@ class CreateTenantTest < ActiveSupport::TestCase body: { name: host.owner.name, slug: host.owner.name.parameterize, - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 201, headers: { 'Content-Type': 'application/json' }, diff --git a/test/interactors/foreman_netbox/sync_host/sync_tenant/find_test.rb b/test/interactors/foreman_netbox/sync_host/sync_tenant/find_test.rb index 893588c..1a3b47c 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_tenant/find_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_tenant/find_test.rb @@ -29,8 +29,8 @@ class FindTenantTest < ActiveSupport::TestCase body: { count: 1, results: [ - { id: 1, name: host.owner.name, slug: host.owner.name.parameterize } - ] + { id: 1, name: host.owner.name, slug: host.owner.name.parameterize }, + ], }.to_json ) @@ -47,7 +47,7 @@ class FindTenantTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 0, - results: [] + results: [], }.to_json ) diff --git a/test/interactors/foreman_netbox/sync_host/sync_tenant/update_test.rb b/test/interactors/foreman_netbox/sync_host/sync_tenant/update_test.rb index e99b7dc..6895321 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_tenant/update_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_tenant/update_test.rb @@ -34,7 +34,7 @@ class UpdateTenantTest < ActiveSupport::TestCase it 'updates tenant' do stub_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/tenancy/tenants/1.json").with( body: { - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 200, headers: { 'Content-Type': 'application/json' }, diff --git a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/create_test.rb b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/create_test.rb index 92a386a..409ddaf 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/create_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/create_test.rb @@ -26,7 +26,7 @@ class CreateVirtualMachineTest < ActiveSupport::TestCase cpus: 2, memory_mb: 512, volumes: [ - OpenStruct.new(size_gb: 128) + OpenStruct.new(size_gb: 128), ] ) ) @@ -53,7 +53,7 @@ class CreateVirtualMachineTest < ActiveSupport::TestCase name: netbox_virtual_machine_params[:name], cluster: cluster.id, tenant: tenant.id, - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 201, headers: { 'Content-Type': 'application/json' }, diff --git a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/create_test.rb b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/create_test.rb index 03b42b1..167e31b 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/create_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/create_test.rb @@ -36,7 +36,7 @@ class CreateClusterTest < ActiveSupport::TestCase body: { name: host.netbox_facet.netbox_params.dig(:cluster, :name), type: cluster_type.id, - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 201, headers: { 'Content-Type': 'application/json' }, diff --git a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/find_test.rb b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/find_test.rb index 7c9d23e..5131313 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/find_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/find_test.rb @@ -30,7 +30,7 @@ class FindClusterTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 1, - results: [{ id: 1, name: host.compute_object.cluster }] + results: [{ id: 1, name: host.compute_object.cluster }], }.to_json ) @@ -47,7 +47,7 @@ class FindClusterTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 0, - results: [] + results: [], }.to_json ) diff --git a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/find_test.rb b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/find_test.rb index ad92b66..65052a8 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/find_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/find_test.rb @@ -35,9 +35,9 @@ class FindClusterTypeTest < ActiveSupport::TestCase { id: 1, name: cluster_type_params[:name], - slug: cluster_type_params[:slug] - } - ] + slug: cluster_type_params[:slug], + }, + ], }.to_json ) @@ -54,7 +54,7 @@ class FindClusterTypeTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 0, - results: [] + results: [], }.to_json ) diff --git a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/update_test.rb b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/update_test.rb index f0bc723..f73b988 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/update_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/update_test.rb @@ -29,7 +29,7 @@ class UpdateClusterTest < ActiveSupport::TestCase it 'updates cluster' do stub_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/virtualization/clusters/1.json").with( body: { - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 200, headers: { 'Content-Type': 'application/json' }, diff --git a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/create_test.rb b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/create_test.rb index 879d205..ecd3c68 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/create_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/create_test.rb @@ -21,7 +21,7 @@ class CreateVirtualMachineInterfacesTest < ActiveSupport::TestCase interfaces: [ FactoryBot.build_stubbed(:nic_base, mac: 'FE:13:C6:44:29:24', ip: '10.0.0.1', ip6: '1500:0:2d0:201::1'), FactoryBot.build_stubbed(:nic_base, mac: 'FE:13:C6:44:29:22', ip: '10.0.0.2', ip6: '1500:0:2d0:201::2'), - FactoryBot.build_stubbed(:nic_base, identifier: nil, mac: nil) + FactoryBot.build_stubbed(:nic_base, identifier: nil, mac: nil), ] ) end @@ -38,13 +38,13 @@ class CreateVirtualMachineInterfacesTest < ActiveSupport::TestCase name: host.interfaces.first.netbox_name, mac_address: host.interfaces.first.mac.upcase, virtual_machine: virtual_machine.id, - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 201, headers: { 'Content-Type': 'application/json' }, body: { id: 1, - name: host.interfaces.first.netbox_name + name: host.interfaces.first.netbox_name, }.to_json ) diff --git a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/delete_test.rb b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/delete_test.rb index c9f2e61..9632e60 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/delete_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/delete_test.rb @@ -21,7 +21,7 @@ class DeleteVirtualMachineInterfacesTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 1, - results: [{ id: interface_id, name: 'eth0' }] + results: [{ id: interface_id, name: 'eth0' }], }.to_json ) end diff --git a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find_test.rb b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find_test.rb index 5a82225..0eaae47 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find_test.rb @@ -24,8 +24,8 @@ class FindVirtualMachineInterfacesTest < ActiveSupport::TestCase body: { count: 1, results: [ - { id: 1 } - ] + { id: 1 }, + ], }.to_json ) @@ -42,11 +42,11 @@ class FindVirtualMachineInterfacesTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 0, - results: [] + results: [], }.to_json ) - assert_equal [], subject.interfaces.map(&:id) + assert_empty subject.interfaces.map(&:id) assert_requested(stub_get) end end diff --git a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/create_test.rb b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/create_test.rb index aa81f81..23ada73 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/create_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/create_test.rb @@ -23,7 +23,7 @@ class CreateVirtualMachineIpAddressesTest < ActiveSupport::TestCase ip6: '1500:0:2d0:201::1', subnet: subnet, subnet6: subnet6 - ) + ), ] ) end @@ -36,7 +36,7 @@ class CreateVirtualMachineIpAddressesTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 0, - results: [] + results: [], }.to_json ) stub_request(:get, "#{Setting[:netbox_url]}/api/ipam/ip-addresses.json").with( @@ -45,7 +45,7 @@ class CreateVirtualMachineIpAddressesTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 1, - results: [{ id: 2 }] + results: [{ id: 2 }], }.to_json ) end @@ -56,7 +56,7 @@ class CreateVirtualMachineIpAddressesTest < ActiveSupport::TestCase address: host.interfaces.first.netbox_ip, assigned_object_type: 'virtualization.vminterface', assigned_object_id: interfaces.first.id, - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 201, headers: { 'Content-Type': 'application/json' }, @@ -68,7 +68,7 @@ class CreateVirtualMachineIpAddressesTest < ActiveSupport::TestCase address: host.interfaces.first.netbox_ip6, assigned_object_type: 'virtualization.vminterface', assigned_object_id: interfaces.first.id, - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 201, headers: { 'Content-Type': 'application/json' }, diff --git a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete_test.rb b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete_test.rb index 4512c4f..e218fda 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete_test.rb @@ -20,7 +20,7 @@ class DeleteVirtualMachineIpAddressesTest < ActiveSupport::TestCase :nic_base, ip: '10.0.0.1', subnet: FactoryBot.build_stubbed(:subnet_ipv4) - ) + ), ] ) end @@ -40,8 +40,8 @@ class DeleteVirtualMachineIpAddressesTest < ActiveSupport::TestCase body: { count: 1, results: [ - { id: interface_id, name: host.interfaces.first.netbox_name } - ] + { id: interface_id, name: host.interfaces.first.netbox_name }, + ], }.to_json ) stub_request(:get, "#{Setting[:netbox_url]}/api/ipam/ip-addresses.json").with( @@ -52,8 +52,8 @@ class DeleteVirtualMachineIpAddressesTest < ActiveSupport::TestCase count: 2, results: [ { id: ip_addresses_v4_id, address: ip_addresses_v4, assigned_object_type: 'virtualization.vminterface', assigned_object_id: interface_id }, - { id: ip_addresses_v6_id, address: ip_addresses_v6, assigned_object_type: 'virtualization.vminterface', assigned_object_id: interface_id } - ] + { id: ip_addresses_v6_id, address: ip_addresses_v6, assigned_object_type: 'virtualization.vminterface', assigned_object_id: interface_id }, + ], }.to_json ) end diff --git a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find_test.rb b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find_test.rb index 1dd42bb..121d2d1 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find_test.rb @@ -23,7 +23,7 @@ class FindVirtualMachineIpAddressesTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 1, - results: [{ id: 1 }] + results: [{ id: 1 }], }.to_json ) @@ -40,11 +40,11 @@ class FindVirtualMachineIpAddressesTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: 0, - results: [] + results: [], }.to_json ) - assert_equal [], subject.ip_addresses.map(&:id) + assert_empty subject.ip_addresses.map(&:id) assert_requested(stub_get) end end diff --git a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/update_test.rb b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/update_test.rb index e52be9f..5121d3a 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/update_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/update_test.rb @@ -17,13 +17,13 @@ class UpdateVirtualMachineIpAddressesTest < ActiveSupport::TestCase { id: 1, address: host.netbox_facet.netbox_params[:ip_addresses].first[:address], - tags: default_tags.map { |t| { id: t.id, name: t.name, slug: t.slug } } + tags: default_tags.map { |t| { id: t.id, name: t.name, slug: t.slug } }, }, { id: 2, address: host.netbox_facet.netbox_params[:ip_addresses].second[:address], - tags: [] - } + tags: [], + }, ] end let(:host) do @@ -37,7 +37,7 @@ class UpdateVirtualMachineIpAddressesTest < ActiveSupport::TestCase ip6: '1600:0:2d0:202::17', subnet: FactoryBot.build_stubbed(:subnet_ipv4, organizations: [], locations: []), subnet6: FactoryBot.build_stubbed(:subnet_ipv6, organizations: [], locations: []) - ) + ), ] ) end @@ -50,7 +50,7 @@ class UpdateVirtualMachineIpAddressesTest < ActiveSupport::TestCase status: 200, headers: { 'Content-Type': 'application/json' }, body: { count: ip_addresses_data.count, - results: ip_addresses_data + results: ip_addresses_data, }.to_json ) end @@ -59,7 +59,7 @@ class UpdateVirtualMachineIpAddressesTest < ActiveSupport::TestCase stub_unexpected_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/ipam/ip-addresses/#{ip_addresses_data.first[:id]}.json") stub_expected_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/ipam/ip-addresses/#{ip_addresses_data.second[:id]}.json").with( body: { - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 200, headers: { 'Content-Type': 'application/json' }, diff --git a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update_test.rb b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update_test.rb index 1ab29d6..68b3d86 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update_test.rb @@ -18,7 +18,7 @@ class UpdateVirtualMachineInterfacesTest < ActiveSupport::TestCase FactoryBot.build_stubbed( :host, interfaces: [ - FactoryBot.build_stubbed(:nic_base, mac: old_mac) + FactoryBot.build_stubbed(:nic_base, mac: old_mac), ] ) end @@ -42,15 +42,15 @@ class UpdateVirtualMachineInterfacesTest < ActiveSupport::TestCase id: 1, name: host.interfaces.first.netbox_name, mac_address: new_mac, - tags: [] - } - ] + tags: [], + }, + ], }.to_json ) stub_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/virtualization/interfaces/1.json").with( body: { mac_address: host.interfaces.first.mac.upcase, - tags: default_tags.map(&:id) + tags: default_tags.map(&:id), }.to_json ).to_return( status: 200, headers: { 'Content-Type': 'application/json' }, @@ -78,9 +78,9 @@ class UpdateVirtualMachineInterfacesTest < ActiveSupport::TestCase mac_address: old_mac, tags: default_tags.map do |tag| { id: tag.id } - end - } - ] + end, + }, + ], }.to_json ) stub_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/virtualization/interfaces/1.json") diff --git a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/update_test.rb b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/update_test.rb index 2f7dafb..a75091c 100644 --- a/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/update_test.rb +++ b/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/update_test.rb @@ -30,14 +30,14 @@ class UpdateVirtualMachineTest < ActiveSupport::TestCase 'primary_ip4' => { 'id' => 1, 'family' => 4, - 'address' => '10.0.0.1/24' + 'address' => '10.0.0.1/24', }, 'primary_ip6' => { 'id' => 2, 'family' => 6, - 'address' => '1600:0:2d0:201::18/64' + 'address' => '1600:0:2d0:201::18/64', }, - 'tags' => virtual_machine_tags + 'tags' => virtual_machine_tags, } ) end @@ -78,7 +78,7 @@ class UpdateVirtualMachineTest < ActiveSupport::TestCase cpus: virtual_machine_data[:vcpus], memory_mb: virtual_machine_data[:memory], volumes: [ - OpenStruct.new(size_gb: virtual_machine_data[:disk]) + OpenStruct.new(size_gb: virtual_machine_data[:disk]), ] ) ) @@ -95,8 +95,8 @@ class UpdateVirtualMachineTest < ActiveSupport::TestCase count: 2, results: [ { id: primary_ip4.id, address: primary_ip4.address.address }, - { id: primary_ip6.id, address: primary_ip6.address.address } - ] + { id: primary_ip6.id, address: primary_ip6.address.address }, + ], }.to_json ) end @@ -142,7 +142,7 @@ class UpdateVirtualMachineTest < ActiveSupport::TestCase cpus: 4, memory_mb: 256, volumes: [ - OpenStruct.new(size_gb: 1024) + OpenStruct.new(size_gb: 1024), ] ) ) @@ -160,7 +160,7 @@ class UpdateVirtualMachineTest < ActiveSupport::TestCase primary_ip6: primary_ip6.id, tenant: tenant.id, vcpus: host.compute_object.cpus, - tags: virtual_machine_tags.map { |t| t['id'] } | default_tags.map(&:id) + tags: virtual_machine_tags.map { |t| t['id'] } | default_tags.map(&:id), }.to_json ).to_return( status: 200, headers: { 'Content-Type': 'application/json' }, diff --git a/test/models/foreman_netbox/netbox_facet_test.rb b/test/models/foreman_netbox/netbox_facet_test.rb index 8c1c4db..7a83931 100644 --- a/test/models/foreman_netbox/netbox_facet_test.rb +++ b/test/models/foreman_netbox/netbox_facet_test.rb @@ -152,7 +152,7 @@ class NetboxFacetTest < ActiveSupport::TestCase memory_mb: memory, volumes: [ OpenStruct.new(size_gb: disk / 2), - OpenStruct.new(size_gb: disk / 2) + OpenStruct.new(size_gb: disk / 2), ] ) ) diff --git a/test/models/foreman_netbox/nics/base_test.rb b/test/models/foreman_netbox/nics/base_test.rb index 6e0d2ac..7e7c83a 100644 --- a/test/models/foreman_netbox/nics/base_test.rb +++ b/test/models/foreman_netbox/nics/base_test.rb @@ -73,7 +73,7 @@ class BaseTest < ActiveSupport::TestCase context 'without ip and ip6' do let(:nic) { FactoryBot.build_stubbed(:nic_base) } - it { assert_equal [], nic.netbox_ips } + it { assert_empty nic.netbox_ips } end end end diff --git a/test/services/foreman_netbox/netbox_attributes_test.rb b/test/services/foreman_netbox/netbox_attributes_test.rb index 2448464..5e6bfd5 100644 --- a/test/services/foreman_netbox/netbox_attributes_test.rb +++ b/test/services/foreman_netbox/netbox_attributes_test.rb @@ -16,7 +16,7 @@ class NetboxParametersTest < ActiveSupport::TestCase let(:expected) do { name: 'Tenant Name', - slug: 'tenant-name' + slug: 'tenant-name', } end @@ -33,7 +33,7 @@ class NetboxParametersTest < ActiveSupport::TestCase let(:expected) do { name: 'device_name', - serial: 'abc123' + serial: 'abc123', } end @@ -62,7 +62,7 @@ class NetboxParametersTest < ActiveSupport::TestCase let(:expected) do { model: 'Product Name', - slug: 'product-name' + slug: 'product-name', } end @@ -74,7 +74,7 @@ class NetboxParametersTest < ActiveSupport::TestCase let(:expected) do { model: 'Unknown', - slug: 'unknown' + slug: 'unknown', } end @@ -120,7 +120,7 @@ class NetboxParametersTest < ActiveSupport::TestCase let(:expected) do { name: 'Site Name', - slug: 'site-name' + slug: 'site-name', } end @@ -137,7 +137,7 @@ class NetboxParametersTest < ActiveSupport::TestCase :nic_base, identifier: expected.first[:name], mac: expected.first[:mac_address] - ) + ), ] ) end @@ -147,8 +147,8 @@ class NetboxParametersTest < ActiveSupport::TestCase name: 'eth1', mac_address: 'FE:13:C6:44:29:24', type: { - value: 'virtual' - } + value: 'virtual', + }, ] end @@ -178,7 +178,7 @@ class NetboxParametersTest < ActiveSupport::TestCase :subnet_ipv6, cidr: expected.second[:address].split('/').second ) - ) + ), ] ) end @@ -188,15 +188,15 @@ class NetboxParametersTest < ActiveSupport::TestCase { address: '10.0.0.1/24', interface: { - name: 'eth1' - } + name: 'eth1', + }, }, { address: '1500:0:2d0:201::1/64', interface: { - name: 'eth2' - } - } + name: 'eth2', + }, + }, ] end @@ -213,7 +213,7 @@ class NetboxParametersTest < ActiveSupport::TestCase memory_mb: expected[:memory], volumes: [ OpenStruct.new(size_gb: expected[:disk] / 2), - OpenStruct.new(size_gb: expected[:disk] / 2) + OpenStruct.new(size_gb: expected[:disk] / 2), ] ) ) @@ -225,7 +225,7 @@ class NetboxParametersTest < ActiveSupport::TestCase name: 'virtual_machine_name', vcpus: 2, memory: 128, - disk: 20 + disk: 20, } end diff --git a/test/services/foreman_netbox/netbox_parameters_comparator_test.rb b/test/services/foreman_netbox/netbox_parameters_comparator_test.rb index 15a2106..ad37240 100644 --- a/test/services/foreman_netbox/netbox_parameters_comparator_test.rb +++ b/test/services/foreman_netbox/netbox_parameters_comparator_test.rb @@ -10,8 +10,8 @@ class NetboxParametersComparatorTest < ActiveSupport::TestCase let(:my_hash) do { device: { - name: 'My device' - } + name: 'My device', + }, } end let(:old_hash) { my_hash } @@ -25,82 +25,82 @@ class NetboxParametersComparatorTest < ActiveSupport::TestCase let(:old_hash) do { device: { - name: 'Old name' + name: 'Old name', }, device_role: { - name: 'SERVER' + name: 'SERVER', }, manufacturer: { - name: 'Manufacturer' + name: 'Manufacturer', }, interfaces: [ { name: 'eth0', type: { - value: 'virtual' - } + value: 'virtual', + }, }, { name: 'eth1', type: { - value: 'virtual' - } + value: 'virtual', + }, }, { name: 'eth2', type: { - value: 'virtual' - } + value: 'virtual', + }, }, { name: 'eth4', mac_address: '00:50:56:84:6D:84', type: { - value: 'virtual' - } - } - ] + value: 'virtual', + }, + }, + ], } end let(:new_hash) do { device: { - name: 'New name' + name: 'New name', }, device_type: { - model: 'Model name' + model: 'Model name', }, manufacturer: { - name: 'Manufacturer' + name: 'Manufacturer', }, interfaces: [ { name: 'eth0', type: { - value: 'virtual' - } + value: 'virtual', + }, }, { name: 'eth1', type: { - value: 'new_type' - } + value: 'new_type', + }, }, { name: 'eth3', type: { - value: 'virtual' - } + value: 'virtual', + }, }, { name: 'eth4', mac_address: '00:50:56:84:6D:84', type: { - value: 'virtual' - } - } - ] + value: 'virtual', + }, + }, + ], } end @@ -111,12 +111,12 @@ class NetboxParametersComparatorTest < ActiveSupport::TestCase device: { name: { old: old_hash.dig(:device, :name), new: new_hash.dig(:device, :name) - } + }, }, interfaces: { added: new_hash[:interfaces].select { |i| %w[eth1 eth3].include?(i[:name]) }, - removed: old_hash[:interfaces].select { |i| %w[eth1 eth2].include?(i[:name]) } - } + removed: old_hash[:interfaces].select { |i| %w[eth1 eth2].include?(i[:name]) }, + }, } end