Fix idempotency around systemd restart
[integration/packaging/puppet-opendaylight.git] / manifests / install.pp
index cd64381af604b705cef0664900174f0914243c6a..56c4909e788f02aea0683a97617122b505e7ab02 100644 (file)
@@ -2,69 +2,64 @@
 #
 # Manages the installation of OpenDaylight.
 #
+# There are two install methods: RPM-based and deb-based. The resulting
+# system state should be functionally equivalent.
+#
 class opendaylight::install {
-  if $opendaylight::install_method == 'rpm' {
-    # Choose Yum URL based on OS (CentOS vs Fedora)
-    $base_url = $::operatingsystem ? {
-      'CentOS' => 'https://copr-be.cloud.fedoraproject.org/results/dfarrell07/OpenDaylight/epel-7-$basearch/',
-      'Fedora' => 'https://copr-be.cloud.fedoraproject.org/results/dfarrell07/OpenDaylight/fedora-$releasever-$basearch/',
-    }
-
+  if $::osfamily == 'RedHat' {
     # Add OpenDaylight's Yum repository
-    yumrepo { 'opendaylight':
+    yumrepo { $opendaylight::rpm_repo:
       # 'ensure' isn't supported with Puppet <3.5
       # Seems to default to present, but docs don't say
       # https://docs.puppetlabs.com/references/3.4.0/type.html#yumrepo
       # https://docs.puppetlabs.com/references/3.5.0/type.html#yumrepo
-      baseurl  => $base_url,
-      descr    => 'OpenDaylight SDN controller',
-      gpgcheck => 0,
+      baseurl  => "http://cbs.centos.org/repos/nfv7-${opendaylight::rpm_repo}/\$basearch/os/",
+      descr    => 'OpenDaylight SDN Controller',
       enabled  => 1,
+      # NB: RPM signing is an active TODO, but is not done. We will enable
+      #     this gpgcheck once the RPM supports it.
+      gpgcheck => 0,
       before   => Package['opendaylight'],
     }
 
     # Install the OpenDaylight RPM
     package { 'opendaylight':
       ensure  => present,
-      require => Yumrepo['opendaylight'],
+      require => Yumrepo[$opendaylight::rpm_repo],
     }
-  }
-  elsif $opendaylight::install_method == 'tarball' {
-    # Download and extract the ODL tarball
-    archive { 'opendaylight-0.2.2':
-      ensure           => present,
-      url              => $opendaylight::tarball_url,
-      # Will end up installing /opt/opendaylight-0.2.2
-      target           => '/opt/opendaylight-0.2.2',
-      # ODL doesn't provide a checksum in the expected path, would fail
-      checksum         => false,
-      # This discards top-level dir of extracted tarball
-      # Required to get proper /opt/opendaylight-<version> path
-      strip_components => 1,
-      # Default timeout is 120s, which may not be enough. See Issue #53:
-      # https://github.com/dfarrell07/puppet-opendaylight/issues/53
-      timeout          => 600,
+    ->
+    # Configure the systemd file with Java options
+    file_line { 'java_options_systemd':
+      ensure => present,
+      path   => '/usr/lib/systemd/system/opendaylight.service',
+      line   => "Environment=_JAVA_OPTIONS=\'${opendaylight::java_opts}\'",
+      match  => '^Environment.*',
+      after  => 'ExecStart=/opt/opendaylight/bin/start',
+    }
+    ~>
+    exec {'reload_systemd_units':
+      command     => 'systemctl daemon-reload',
+      path        => '/bin',
+      refreshonly => true,
     }
+  }
+
+  elsif $::osfamily == 'Debian'{
+
+    include apt
+
+    # Add ODL ppa repository
+    apt::ppa{ $opendaylight::deb_repo: }
 
-    # Download ODL systemd .service file and put in right location
-    archive { 'opendaylight-systemd':
-      ensure           => present,
-      url              => $opendaylight::unitfile_url,
-      # Will end up installing /usr/lib/systemd/system/opendaylight.service
-      target           => '/usr/lib/systemd/system/',
-      # Required by archive mod for correct exec `creates` param
-      root_dir         => 'opendaylight.service',
-      # ODL doesn't provide a checksum in the expected path, would fail
-      checksum         => false,
-      # This discards top-level dir of extracted tarball
-      # Required to get proper /opt/opendaylight-<version> path
-      strip_components => 1,
-      # May end up with an HTML redirect output in a text file without this
-      # Note that the curl'd down file would still have a .tar.gz name
-      follow_redirects => true,
+    # Install Opendaylight .deb pkg
+    package { 'opendaylight':
+      ensure  => present,
+      require => Apt::Ppa[$opendaylight::deb_repo],
     }
+
+    Apt::Ppa[$opendaylight::deb_repo] -> Package['opendaylight']
   }
   else {
-    fail("Unknown install method: ${opendaylight::install_method}")
+    fail("Unknown operating system method: ${::osfamily}")
   }
 }