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

yast / yast-network / 4859584370

pending completion
4859584370

Pull #1327

github

Unknown Committer
Unknown Commit Message
Pull Request #1327: [WIP] Firmware configured interface

81 of 81 new or added lines in 7 files covered. (100.0%)

9240 of 11493 relevant lines covered (80.4%)

20.0 hits per line

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

90.12
/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 "network/wicked"
1✔
23
require "y2network/presenters/interface_summary"
1✔
24
require "y2network/presenters/s390_group_device_summary"
1✔
25

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

30
module Y2Network
1✔
31
  module Widgets
1✔
32
    class InterfacesTable < CWM::Table
1✔
33
      include Yast::Wicked
1✔
34

35
      def initialize(description)
1✔
36
        textdomain "network"
19✔
37

38
        @description = description
19✔
39
        @handlers = []
19✔
40
      end
41

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

51
      def opt
1✔
52
        [:notify, :immediate]
2✔
53
      end
54

55
      def add_handler(handler)
1✔
56
        @handlers << handler
×
57
      end
58

59
      def handle
1✔
60
        @description.value = create_description
10✔
61
        refresh_handlers
10✔
62

63
        nil
64
      end
65

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

73
        items_list
5✔
74
      end
75

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

90
        change_items(items)
×
91
        handle
×
92
      end
93

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

101
    private
1✔
102

103
      def refresh_handlers
1✔
104
        @handlers.each(&:init)
10✔
105
      end
106

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

112
        return "" unless conn
5✔
113

114
        parent = conn.find_parent(config.connections)
4✔
115

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

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

121
        ""
4✔
122
      end
123

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

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

142
      def interface_protocol(connection)
1✔
143
        return _("Not Configured") if connection.nil?
8✔
144

145
        bootproto = connection.bootproto.name
8✔
146

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

155
      def configuration_for(interface, connection)
1✔
156
        return interface_protocol(connection) unless connection.nil?
10✔
157

158
        firmware_configured?(interface) ? _("Configured by firmware") : _("Not Configured")
2✔
159
      end
160

161
      def selected_item
1✔
162
        config.interfaces.by_name(value) || config.s390_devices.by_id(value)
10✔
163
      end
164

165
      def config
1✔
166
        Yast::Lan.yast_config
44✔
167
      end
168

169
      def create_description
1✔
170
        summary = Presenters.const_get("#{summary_class_name}Summary")
10✔
171
        summary.new(value, config).text
10✔
172
      end
173

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

183
        hwinfo = device.hardware
14✔
184
        (hwinfo&.present?) ? hwinfo.description : device.name
14✔
185
      end
186

187
      def summary_class_name
1✔
188
        (selected_item.class.to_s == "Y2Network::S390GroupDevice") ? "S390GroupDevice" : "Interface"
10✔
189
      end
190

191
      def firmware_configured?(interface)
1✔
192
        firmware_interfaces.include?(interface.name)
2✔
193
      end
194
    end
195
  end
196
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