Skip to content

Commit 373e9b1

Browse files
committed
pkg/updateengine: rewrite tests and code to use new dbus package
This is a safe step before moving creation of D-Bus connection to agent and eventually agent CLI code, which however requires development of tests on the agent code itself. Signed-off-by: Mateusz Gozdek <[email protected]>
1 parent b3b7acf commit 373e9b1

File tree

4 files changed

+310
-372
lines changed

4 files changed

+310
-372
lines changed

pkg/agent/agent.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"k8s.io/klog/v2"
2828

2929
"github.com/flatcar-linux/flatcar-linux-update-operator/pkg/constants"
30+
"github.com/flatcar-linux/flatcar-linux-update-operator/pkg/dbus"
3031
"github.com/flatcar-linux/flatcar-linux-update-operator/pkg/k8sutil"
3132
"github.com/flatcar-linux/flatcar-linux-update-operator/pkg/updateengine"
3233
)
@@ -67,7 +68,7 @@ func New(node string, reapTimeout time.Duration) (*Klocksmith, error) {
6768
nc := kc.CoreV1().Nodes()
6869

6970
// Set up update_engine client.
70-
updateEngineClient, err := updateengine.New(updateengine.DBusSystemPrivateConnector)
71+
updateEngineClient, err := updateengine.New(dbus.SystemPrivateConnector)
7172
if err != nil {
7273
return nil, fmt.Errorf("establishing connection to update_engine dbus: %w", err)
7374
}

pkg/updateengine/client.go

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ package updateengine
1616

1717
import (
1818
"fmt"
19-
"os"
20-
"strconv"
2119

2220
godbus "github.com/godbus/dbus/v5"
21+
22+
"github.com/flatcar-linux/flatcar-linux-update-operator/pkg/dbus"
2323
)
2424

2525
const (
@@ -52,49 +52,27 @@ type Client interface {
5252

5353
// DBusConnection is set of methods which client expects D-Bus connection to implement.
5454
type DBusConnection interface {
55-
Auth([]godbus.Auth) error
56-
Hello() error
5755
Close() error
5856
AddMatchSignal(...godbus.MatchOption) error
5957
Signal(chan<- *godbus.Signal)
6058
Object(string, godbus.ObjectPath) godbus.BusObject
6159
}
6260

63-
// DBusConnector is a constructor function providing D-Bus connection.
64-
type DBusConnector func() (DBusConnection, error)
65-
66-
// DBusSystemPrivateConnector is a standard update_engine connector using system bus.
67-
func DBusSystemPrivateConnector() (DBusConnection, error) {
68-
return godbus.SystemBusPrivate()
61+
type caller interface {
62+
Call(method string, flags godbus.Flags, args ...interface{}) *godbus.Call
6963
}
7064

7165
type client struct {
7266
conn DBusConnection
73-
object godbus.BusObject
67+
object caller
7468
ch chan *godbus.Signal
7569
}
7670

7771
// New creates new instance of Client and initializes it.
78-
func New(newConnection DBusConnector) (Client, error) {
79-
conn, err := newConnection()
72+
func New(connector dbus.Connector) (Client, error) {
73+
conn, err := dbus.New(connector)
8074
if err != nil {
81-
return nil, fmt.Errorf("opening private connection to system bus: %w", err)
82-
}
83-
84-
methods := []godbus.Auth{godbus.AuthExternal(strconv.Itoa(os.Getuid()))}
85-
86-
if err := conn.Auth(methods); err != nil {
87-
// Best effort closing the connection.
88-
_ = conn.Close()
89-
90-
return nil, fmt.Errorf("authenticating to system bus: %w", err)
91-
}
92-
93-
if err := conn.Hello(); err != nil {
94-
// Best effort closing the connection.
95-
_ = conn.Close()
96-
97-
return nil, fmt.Errorf("sending hello to system bus: %w", err)
75+
return nil, fmt.Errorf("creating D-Bus client: %w", err)
9876
}
9977

10078
matchOptions := []godbus.MatchOption{

pkg/updateengine/client_integration_test.go

Lines changed: 0 additions & 244 deletions
This file was deleted.

0 commit comments

Comments
 (0)