Skip to content

Commit

Permalink
Add NmConnection.all to get find connection files
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Feb 4, 2021
1 parent 31837b3 commit a9fd945
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib/cfa/nm_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

require "cfa/base_model"

Yast.import "Installation"

module CFA
# Class to handle NetworkManager connection configuration files
#
Expand All @@ -31,7 +33,18 @@ class NmConnection < BaseModel
KNOWN_SECTIONS = [
"bridge", "connection", "ethernet", "ipv4", "ipv6", "vlan", "wifi", "wifi_security"
].freeze
SYSTEM_CONNECTIONS_DIR = "/etc/NetworkManager/system-connections".freeze

class << self
# Returns all connection definition files
#
# @return [Array<NmConnection>]
def all
directory = File.join(Yast::Installation.destdir, SYSTEM_CONNECTIONS_DIR)
files = Dir[File.join(directory, "*.nmconnection")].to_a
files.map { |f| new(f) }
end
end
# Constructor
#
# @param path [String] File path
Expand Down
11 changes: 11 additions & 0 deletions test/cfa/nm_connection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ def file_path(filename)
subject { described_class.new(conn_file) }
let(:conn_file) { file_path("some_wifi.nmconnection") }

describe ".all" do
around do |example|
change_scr_root(File.join(DATA_PATH, "instsys"), &example)
end

it "returns all connections files" do
files = described_class.all
expect(files).to be_all(CFA::NmConnection)
end
end

describe "#connection" do
before { subject.load }

Expand Down

0 comments on commit a9fd945

Please sign in to comment.