summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2016-08-16 09:40:10 -0400
committerPatrick Williams <patrick@stwcx.xyz>2016-09-06 11:13:40 +0000
commitbe42fe9c200f9accfad758d03d36e06cdead1033 (patch)
tree66c909444956c8ff9e96f90ad5daf308af677f94
parent9ca070ccdba1a518c0f3a901c46c474bde67b50e (diff)
downloadtalos-openbmc-be42fe9c200f9accfad758d03d36e06cdead1033.tar.gz
talos-openbmc-be42fe9c200f9accfad758d03d36e06cdead1033.zip
classes-dbus: general refactoring
Use the SystemdUnit parser to determine unit file properties. Remove DBUS_ACTIVATED_SERVICE: Rather, infer whether or not the service should be dbus activated based on SystemdUnit results and act accordingly. Change-Id: I87eed79b088d8531153e9d366e0f2d2e5ea73e5e Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
-rw-r--r--meta-phosphor/classes/obmc-phosphor-dbus-service.bbclass143
-rw-r--r--meta-phosphor/common/recipes-phosphor/dbus/obmc-mapper.bb2
-rw-r--r--meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-pydbus/obmc-phosphor-example-pydbus.bb2
-rw-r--r--meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/obmc-phosphor-example-sdbus.bb2
4 files changed, 73 insertions, 76 deletions
diff --git a/meta-phosphor/classes/obmc-phosphor-dbus-service.bbclass b/meta-phosphor/classes/obmc-phosphor-dbus-service.bbclass
index ebe87af74..029d26093 100644
--- a/meta-phosphor/classes/obmc-phosphor-dbus-service.bbclass
+++ b/meta-phosphor/classes/obmc-phosphor-dbus-service.bbclass
@@ -3,9 +3,9 @@
# DBUS_PACKAGES ?= "${PN}"
# The list of packages to which files should be added.
#
-# DBUS_SERVICE_${PN} += "org.openbmc.Foo"
+# DBUS_SERVICE_${PN} += "org.openbmc.Foo.service"
# A list of dbus service names. The class will look for a
-# dbus configuration file with the same name with .conf
+# dbus configuration file with the same base name with .conf
# appended. If one is found, it is added to the package
# and used verbatim. If it is not found, a default one
# (with very open permissions) is generated and used.
@@ -13,18 +13,11 @@
# Additionally the class will instantiate obmc-phosphor-systemd
# with any SYSTEMD_SERVICE_%s variables translated appropriately.
#
-# DBUS_ACTIVATED_SERVICE_${PN} += "org.openbmc.Foo"
-# A list of services that should have dbus activation configured.
-# Services that appear here need not be in DBUS_SERVICE_%s.
-# If used, the search pattern for the systemd unit file is
-# changed to be dbus-%s.service. The class will look for a
-# dbus activation file with the same name with .service appended.
-# If one is found, it added to the package and used verbatim.
-# If it is not found, a default one is generated and used.
-#
-# DBUS_USER_${PN} = "dbususer"
-# DBUS_USER_${unit} = "dbususer"
-# The user a service/pkg should be configured to run as.
+# If a service begins with 'dbus-' DBus activation will be
+# configured. The class will look for an activation file
+# with the 'dbus-' prefix removed. If found, it is added to
+# the package and used verbatim. If it is not found, a default
+# one is generated and used.
inherit dbus-dir
@@ -40,37 +33,49 @@ _DEFAULT_DBUS_ACTIVATIONS=""
python dbus_do_postinst() {
- def make_default_dbus_config(d, service, user):
+ def make_default_dbus_config(d, unit, user):
+ bus = unit.base
+ if unit.is_template:
+ bus = '%s*' % bus
+
path = d.getVar('D', True)
path += d.getVar('dbus_system_confdir', True)
- with open('%s/%s.conf' % (path, service), 'w+') as fd:
+ with open('%s/%s.conf' % (path, unit.base), 'w+') as fd:
fd.write('<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"\n')
fd.write(' "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">\n')
fd.write('<busconfig>\n')
fd.write(' <policy user="%s">\n' % user)
- fd.write(' <allow own="%s"/>\n' % service)
- fd.write(' <allow send_destination="%s"/>\n' % service)
+ fd.write(' <allow own="%s"/>\n' % bus)
+ fd.write(' <allow send_destination="%s"/>\n' % bus)
fd.write(' </policy>\n')
fd.write('</busconfig>\n')
fd.close()
- def make_default_dbus_activation(d, service, user):
+ def make_default_dbus_activation(d, unit, user):
+ dest = unit.base
+ sd_unit = unit.name
+ if unit.is_instance:
+ dest = '%s.%s' % (unit.base, unit.instance)
+ sd_unit = '%s@%s' % (unit.base, unit.instance)
+
path = d.getVar('D', True)
path += d.getVar('dbus_system_servicesdir', True)
- with open('%s/%s.service' % (path, service), 'w+') as fd:
+ with open('%s/%s.service' % (path, dest), 'w+') as fd:
fd.write('[D-BUS Service]\n')
- fd.write('Name=%s\n' % service)
+ fd.write('Name=%s\n' % dest)
fd.write('Exec=/bin/false\n')
fd.write('User=%s\n' % user)
- fd.write('SystemdService=dbus-%s.service\n' % service)
+ fd.write('SystemdService=dbus-%s.service\n' % sd_unit)
fd.close()
for service_user in listvar_to_list(d, '_DEFAULT_DBUS_CONFIGS'):
- make_default_dbus_config(d, *service_user.split(':'))
+ service, user = service_user.split(':')
+ make_default_dbus_config(d, SystemdUnit(service), user)
for service_user in listvar_to_list(d, '_DEFAULT_DBUS_ACTIVATIONS'):
- make_default_dbus_activation(d, *service_user.split(':'))
+ service, user = service_user.split(':')
+ make_default_dbus_activation(d, SystemdUnit(service), user)
}
@@ -79,77 +84,69 @@ python() {
def get_user(d, service, pkg):
user = d.getVar(
- 'DBUS_USER_%s' % service, True)
+ 'SYSTEMD_USER_%s' % service, True)
if user is None:
user = d.getVar(
- 'DBUS_USER_%s' % pkg, True) or 'root'
+ 'SYSTEMD_USER_%s' % pkg, True) or 'root'
return user
- def add_dbus_config(d, service, pkg):
- path = bb.utils.which(searchpaths, '%s.conf' % service)
+ def add_dbus_config(d, unit, pkg):
+ path = bb.utils.which(searchpaths, '%s.conf' % unit.base)
if not os.path.isfile(path):
- user = get_user(d, service, pkg)
+ user = get_user(d, unit.name, pkg)
set_append(d, '_DEFAULT_DBUS_CONFIGS', '%s:%s' % (
- service, user))
+ unit.name, user))
else:
- set_append(d, 'SRC_URI', 'file://%s.conf' % service)
- set_append(d, '_INSTALL_DBUS_CONFIGS', '%s.conf' % service)
+ set_append(d, 'SRC_URI', 'file://%s.conf' % unit.base)
+ set_append(d, '_INSTALL_DBUS_CONFIGS', '%s.conf' % unit.base)
set_append(d, 'FILES_%s' % pkg, '%s%s.conf' \
- % (d.getVar('dbus_system_confdir', True), service))
-
-
- def add_sd_unit(d, prefix, service, pkg):
- set_append(
- d, 'SYSTEMD_SERVICE_%s' % pkg, '%s%s.service' % (
- prefix, service))
- set_append(d, 'SYSTEMD_SUBSTITUTIONS',
- 'BUSNAME:%s:%s%s.service' % (service, prefix, service))
+ % (d.getVar('dbus_system_confdir', True), unit.base))
- def add_sd_user(d, prefix, service, pkg):
- var = None
- user = d.getVar(
- 'DBUS_USER_%s' % service, True)
- if user:
- var = 'SYSTEMD_USER_%s%s.service' % (prefix, service)
- else:
- user = d.getVar(
- 'DBUS_USER_%s' % pkg, True)
- if user:
- var = 'SYSTEMD_USER_%s' % pkg
+ def add_dbus_activation(d, unit, pkg):
+ if not unit.is_activated or unit.is_template:
+ return
+ search_match = '%s.service' % unit.base
+ if unit.is_instance:
+ search_match = '%s.%s.service' % (unit.base, unit.instance)
- if var and user not in listvar_to_list(d, var):
- set_append(d, var, user)
+ path = bb.utils.which(searchpaths, search_match)
-
- def add_dbus_activation(d, service, pkg):
- path = bb.utils.which(searchpaths, '%s.service' % service)
if not os.path.isfile(path):
- user = get_user(d, service, pkg)
+ user = get_user(d, unit.base, pkg)
set_append(d, '_DEFAULT_DBUS_ACTIVATIONS', '%s:%s' % (
- service, user))
+ unit.name, user))
else:
- set_append(d, 'SRC_URI', 'file://%s.service' % service)
- set_append(d, '_INSTALL_DBUS_ACTIVATIONS', '%s.service' % service)
- set_append(d, 'FILES_%s' % pkg, '%s%s.service' \
- % (d.getVar('dbus_system_servicesdir', True), service))
+ set_append(d, 'SRC_URI', 'file://%s' % search_match)
+ set_append(d, '_INSTALL_DBUS_ACTIVATIONS', search_match)
+ set_append(d, 'FILES_%s' % pkg, '%s%s' \
+ % (d.getVar('dbus_system_servicesdir', True), search_match))
for pkg in listvar_to_list(d, 'DBUS_PACKAGES'):
if pkg not in (d.getVar('SYSTEMD_PACKAGES', True) or ''):
set_append(d, 'SYSTEMD_PACKAGES', pkg)
- services = listvar_to_list(d, 'DBUS_SERVICE_%s' % pkg)
- auto = listvar_to_list(d, 'DBUS_ACTIVATED_SERVICE_%s' % pkg)
-
- for service in set(services).union(auto):
- prefix = 'dbus-' if service in auto else ''
- add_dbus_config(d, service, pkg)
- add_sd_unit(d, prefix, service, pkg)
- add_sd_user(d, prefix, service, pkg)
- if prefix:
- add_dbus_activation(d, service, pkg)
+ svc = listvar_to_list(d, 'DBUS_SERVICE_%s' % pkg)
+ svc = [SystemdUnit(x) for x in svc]
+ inst = [x for x in svc if x.is_instance]
+ tmpl = [x.template for x in svc if x.is_instance]
+ tmpl = list(set(tmpl))
+ tmpl = [SystemdUnit(x) for x in tmpl]
+ svc = [x for x in svc if not x.is_instance]
+
+ for unit in inst:
+ set_append(
+ d, 'SYSTEMD_SERVICE_%s' % pkg, unit.name)
+
+ for unit in tmpl + svc:
+ add_dbus_config(d, unit, pkg)
+ add_dbus_activation(d, unit, pkg)
+ set_append(
+ d, 'SYSTEMD_SERVICE_%s' % pkg, unit.name)
+ set_append(d, 'SYSTEMD_SUBSTITUTIONS',
+ 'BUSNAME:%s:%s' % (unit.base, unit.name))
}
diff --git a/meta-phosphor/common/recipes-phosphor/dbus/obmc-mapper.bb b/meta-phosphor/common/recipes-phosphor/dbus/obmc-mapper.bb
index ea38559d6..b516f6854 100644
--- a/meta-phosphor/common/recipes-phosphor/dbus/obmc-mapper.bb
+++ b/meta-phosphor/common/recipes-phosphor/dbus/obmc-mapper.bb
@@ -11,7 +11,7 @@ inherit setuptools
DEPENDS += "systemd"
-DBUS_SERVICE_${PN} += "org.openbmc.ObjectMapper"
+DBUS_SERVICE_${PN} += "org.openbmc.ObjectMapper.service"
RDEPENDS_${PN} += " \
python-xml \
python-dbus \
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-pydbus/obmc-phosphor-example-pydbus.bb b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-pydbus/obmc-phosphor-example-pydbus.bb
index 7e3e90713..a6c513dda 100644
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-pydbus/obmc-phosphor-example-pydbus.bb
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-pydbus/obmc-phosphor-example-pydbus.bb
@@ -2,7 +2,7 @@ SUMMARY = "Phosphor OpenBMC BSP Example Application"
DESCRIPTION = "Phosphor OpenBMC QEMU BSP example implementation."
PR = "r1"
-DBUS_SERVICE_${PN} += "org.openbmc.examples.PythonService"
+DBUS_SERVICE_${PN} += "org.openbmc.examples.PythonService.service"
inherit obmc-phosphor-pydbus-service
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/obmc-phosphor-example-sdbus.bb b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/obmc-phosphor-example-sdbus.bb
index 541aa7943..a19b6848f 100644
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/obmc-phosphor-example-sdbus.bb
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-example-sdbus/obmc-phosphor-example-sdbus.bb
@@ -2,7 +2,7 @@ SUMMARY = "Phosphor OpenBMC BSP Example Application"
DESCRIPTION = "Phosphor OpenBMC QEMU BSP example implementation."
PR = "r1"
-DBUS_SERVICE_${PN} += "org.openbmc.examples.SDBusService"
+DBUS_SERVICE_${PN} += "org.openbmc.examples.SDBusService.service"
S = "${WORKDIR}"
SRC_URI += "file://Makefile \
OpenPOWER on IntegriCloud