• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yast / yast-network / 4883614202

pending completion
4883614202

Pull #1327

github

Unknown Committer
Unknown Commit Message
Pull Request #1327: Firmware configured interface (bsc#1209589)

85 of 85 new or added lines in 9 files covered. (100.0%)

9251 of 11501 relevant lines covered (80.44%)

20.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.61
/src/lib/y2network/widgets/interfaces_table.rb
1
# Copyright (c) [2019-2021] SUSE LLC
2
#
3
# All Rights Reserved.
4
#
5
# This program is free software; you can redistribute it and/or modify it
6
# under the terms of version 2 of the GNU General Public License as published
7
# by the Free Software Foundation.
8
#
9
# This program is distributed in the hope that it will be useful, but WITHOUT
10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12
# more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with this program; if not, contact SUSE LLC.
16
#
17
# To contact SUSE LLC about this file by physical or electronic mail, you may
18
# find current contact information at www.suse.com.
19

20
require "yast"
1✔
21
require "cwm/table"
1✔
22
require "y2network/presenters/interface_summary"
1✔
23
require "y2network/presenters/s390_group_device_summary"
1✔
24

25
Yast.import "Lan"
1✔
26
Yast.import "Popup"
1✔
27
Yast.import "UI"
1✔
28

29
module Y2Network
1✔
30
  module Widgets
1✔
31
    class InterfacesTable < CWM::Table
1✔
32
      def initialize(description)
1✔
33
        textdomain "network"
20✔
34

35
        @description = description
20✔
36
        @handlers = []
20✔
37
      end
38

39
      def header
1✔
40
        [
2✔
41
          _("Name"),
42
          _("IP Address"),
43
          _("Device"),
44
          _("Note")
45
        ]
46
      end
47

48
      def opt
1✔
49
        [:notify, :immediate]
2✔
50
      end
51

52
      def add_handler(handler)
1✔
53
        @handlers << handler
×
54
      end
55

56
      def handle
1✔
57
        @description.value = create_description
11✔
58
        refresh_handlers
11✔
59

60
        nil
61
      end
62

63
      def items
1✔
64
        items_list = []
5✔
65
        config.interfaces.each { |i| items_list << interface_item(i) }
15✔
66
        config.s390_devices.select(&:offline?).each do |device|
5✔
67
          items_list << device_item(device)
5✔
68
        end
69

70
        items_list
5✔
71
      end
72

73
      # Workaround for usage in old CWM which also cache content of cwm items
74
      def init
1✔
75
        if config.backend?(:network_manager)
×
76
          Yast::Popup.Warning(
×
77
            _(
78
              "Network is currently handled by NetworkManager\n" \
79
              "or completely disabled. YaST is unable to configure some options."
80
            )
81
          )
82
          # switch to global tab
83
          Yast::UI.FakeUserInput("ID" => "global")
×
84
          return
×
85
        end
86

87
        change_items(items)
×
88
        handle
×
89
      end
90

91
      def help
1✔
92
        _(
1✔
93
          "<p><b><big>Overview</big></b><br>\n" \
94
           "Obtain an overview of the network interfaces configuration.</p>\n"
95
        )
96
      end
97

98
    private
1✔
99

100
      def refresh_handlers
1✔
101
        @handlers.each(&:init)
11✔
102
      end
103

104
      def note(interface, conn)
1✔
105
        if interface.name != interface.old_name && interface.old_name
10✔
106
          return format("%s -> %s", interface.old_name, interface.name)
5✔
107
        end
108

109
        return "" unless conn
5✔
110

111
        parent = conn.find_parent(config.connections)
4✔
112

113
        # TRANSLATORS: %s is a name of a bond/bridge device
114
        return format(_("included in %s"), parent.name) if parent
4✔
115

116
        return format(_("parent: %s"), conn.parent_device) if conn.type.vlan?
4✔
117

118
        ""
4✔
119
      end
120

121
      # Constructs device description for inactive s390 devices
122
      def device_item(device)
1✔
123
        [device.id, description_for(device), _("Not activated"), device.id, ""]
5✔
124
      end
125

126
      # Generic device description handler
127
      def interface_item(interface)
1✔
128
        conn = config.connections.by_name(interface.name)
10✔
129
        [
10✔
130
          # first is (item) ID in table
131
          interface.name,
132
          description_for(interface, conn),
133
          configuration_for(interface, conn),
134
          interface.name,
135
          note(interface, conn)
136
        ]
137
      end
138

139
      def interface_protocol(connection)
1✔
140
        return _("Not configured") if connection.nil?
8✔
141

142
        bootproto = connection.bootproto.name
8✔
143

144
        if bootproto == "static"
8✔
145
          ip_config = connection.ip
8✔
146
          ip_config ? ip_config.address.to_s : ""
8✔
147
        else
148
          bootproto.upcase
×
149
        end
150
      end
151

152
      def configuration_for(interface, connection)
1✔
153
        return interface_protocol(connection) unless connection.nil?
10✔
154

155
        interface.firmware_configured? ? _("Configured by firmware") : _("Not configured")
2✔
156
      end
157

158
      def selected_item
1✔
159
        config.interfaces.by_name(value) || config.s390_devices.by_id(value)
11✔
160
      end
161

162
      def config
1✔
163
        Yast::Lan.yast_config
46✔
164
      end
165

166
      def create_description
1✔
167
        summary = Presenters.const_get("#{summary_class_name}Summary")
11✔
168
        summary.new(value, config).text
11✔
169
      end
170

171
      # Returns the connection description if given or the device friendly name if not
172
      #
173
      # @param device [Interface, S390GroupDevice] Network device
174
      # @param conn [ConnectionConfig::Base, nil] Connection configuration
175
      # @return [String] Connection description if given or the friendly name for the interface (
176
      #   description or name) if not
177
      def description_for(device, conn = nil)
1✔
178
        return conn.description unless conn&.description.to_s.empty?
15✔
179

180
        hwinfo = device.hardware
14✔
181
        (hwinfo&.present?) ? hwinfo.description : device.name
14✔
182
      end
183

184
      def summary_class_name
1✔
185
        (selected_item.class.to_s == "Y2Network::S390GroupDevice") ? "S390GroupDevice" : "Interface"
11✔
186
      end
187

188
      def firmware_configured?(interface)
1✔
189
        firmware_interfaces.include?(interface.name)
×
190
      end
191
    end
192
  end
193
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc