1#!/usr/bin/env python3

2# Copyright 2019 Canonical Ltd.

3# All rights reserved.

4#

5# Written by:

6# Authors: Jonathan Cave <jonathan.cave@canonical.com>

7

8 import sys

9

10 from checkbox_support.snap_utils.snapd import Snapd

11

12

13 if __name__ == "__main__":

14 if len(sys.argv) < 3:

15 raise SystemExit("Usage: plug_connected_test.py SNAP PLUG")

16 snap_name = sys.argv[1]

17 plug_name = sys.argv[2]

18

19 data = Snapd().interfaces()

20 for plug in data.get("plugs", []):

21 if plug["snap"] == snap_name and plug["plug"] == plug_name:

22 if "connections" in plug:

23 print(

24 "{}:{} is connected to:".format(plug["snap"], plug["plug"])

25 )

26 for slot in plug["connections"]:

27 print("{}:{}".format(slot["snap"], slot["slot"]))

28 else:

29 raise SystemExit(

30 "ERROR: {}:{} is not connected".format(

31 plug["snap"], plug["plug"]

32 )

33 )