Skip to content

Commit

Permalink
Remove unused functions + drop series before focal
Browse files Browse the repository at this point in the history
We wish to remove the concept of a series from the juju extended
codebase. Series is something that juju/packaging relies on quite
heavily

We can change this by removing a number of unused functions/methods
which take in series as parameters.

Also, since we no longer support series before focal, we can take out a
lot of the special cases and make the PackingingConfigurers series
agnostic
  • Loading branch information
jack-w-shaw committed Apr 12, 2024
1 parent 6786bbb commit a2c4439
Show file tree
Hide file tree
Showing 18 changed files with 18 additions and 459 deletions.
22 changes: 1 addition & 21 deletions config/apt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
package config_test

import (
"fmt"

jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"

Expand All @@ -20,29 +18,13 @@ type AptSuite struct {
}

func (s *AptSuite) SetUpSuite(c *gc.C) {
s.pacconfer = config.NewAptPackagingConfigurer(testedSeriesUbuntu)
s.pacconfer = config.NewAptPackagingConfigurer()
}

func (s *AptSuite) TestDefaultPackages(c *gc.C) {
c.Assert(s.pacconfer.DefaultPackages(), gc.DeepEquals, config.UbuntuDefaultPackages)
}

func (s *AptSuite) TestGetPackageNameForSeriesSameSeries(c *gc.C) {
for _, pack := range testedPackages {
res, err := s.pacconfer.GetPackageNameForSeries(pack, testedSeriesUbuntu)
c.Assert(err, jc.ErrorIsNil)
c.Assert(res, gc.Equals, pack)
}
}

func (s *AptSuite) TestGetPackageNameForSeriesErrors(c *gc.C) {
for _, pack := range testedPackages {
res, err := s.pacconfer.GetPackageNameForSeries(pack, "some-other-series")
c.Assert(res, gc.Equals, "")
c.Assert(err, gc.ErrorMatches, fmt.Sprintf("no equivalent package found for series %s: %s", "some-other-series", pack))
}
}

func (s *AptSuite) TestIsCloudArchivePackage(c *gc.C) {
testedPacks := []string{
"random",
Expand Down Expand Up @@ -85,8 +67,6 @@ func (s *AptSuite) TestRenderPreferences(c *gc.C) {
func (s *AptSuite) TestApplyCloudArchiveTarget(c *gc.C) {
res := s.pacconfer.ApplyCloudArchiveTarget("some-package")
c.Assert(res, gc.DeepEquals, []string{
"--target-release",
"precise-updates/cloud-tools",
"some-package",
})
}
18 changes: 0 additions & 18 deletions config/centos_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

package config

import (
"github.com/juju/packaging/v2"
)

const (
// CentOSCloudArchiveUrl is the url of the (future) cloud archive for CentOS.
// TODO (people of the distant future): add this when it is available.
Expand Down Expand Up @@ -39,17 +35,3 @@ var cloudArchivePackagesCentOS = map[string]struct{}{
// CentOS 7+ especially for Juju is to ever occur, please add the relevant
// package listings here.
}

// centOSToUbuntuPackageNameMap is a map for converting package names from
// their names as found in CentOS repositories to their equivalent in Ubuntu.
// It is implemented as the flipped package mapper for Ubuntu.
var centOSToUbuntuPackageNameMap = flipMap(ubuntuToCentOSPackageNameMap)

// configureCloudArchiveSourceCentOS is a helper function which returns the
// cloud archive PackageSource and PackagePreferences for the given series for
// CentOS machines.
func configureCloudArchiveSourceCentOS(series string) (packaging.PackageSource, packaging.PackagePreferences) {
// TODO (aznashwan, all): implement this when the
// archive for CentOS goes up.
return packaging.PackageSource{}, packaging.PackagePreferences{}
}
29 changes: 0 additions & 29 deletions config/configurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@

package config

import (
"github.com/juju/errors"
)

// baseConfigurer is the base type of a Configurer object.
type baseConfigurer struct {
series string
defaultPackages []string
cloudArchivePackages map[string]struct{}
}
Expand All @@ -20,30 +15,6 @@ func (c *baseConfigurer) DefaultPackages() []string {
return c.defaultPackages
}

// GetPackageNameForSeries is defined on the PackagingConfigurer interface.
func (c *baseConfigurer) GetPackageNameForSeries(pack, series string) (string, error) {
if c.series == series {
return pack, nil
}

// TODO(aznashwan): find a more deterministic way of filtering series that
// does not imply importing version from core.
switch series {
case "centos7":
res, ok := centOSToUbuntuPackageNameMap[pack]
if !ok {
return "", errors.Errorf("no equivalent package found for series %s: %s", series, pack)
}
return res, nil
default:
res, ok := ubuntuToCentOSPackageNameMap[pack]
if !ok {
return "", errors.Errorf("no equivalent package found for series %s: %s", series, pack)
}
return res, nil
}
}

// IsCloudArchivePackage is defined on the PackagingConfigurer interface.
func (c *baseConfigurer) IsCloudArchivePackage(pack string) bool {
_, ok := c.cloudArchivePackages[pack]
Expand Down
2 changes: 1 addition & 1 deletion config/configurer_apt.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ func (c *aptConfigurer) RenderPreferences(prefs packaging.PackagePreferences) (s

// ApplyCloudArchiveTarget is defined on the PackagingConfigurer interface.
func (c *aptConfigurer) ApplyCloudArchiveTarget(pack string) []string {
return []string{"--target-release", getTargetReleaseSpecifierUbuntu(c.series), pack}
return []string{pack}
}
9 changes: 0 additions & 9 deletions config/constants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ package config_test
import "github.com/juju/packaging/v2"

var (
// testedSeriesUbuntu is simply the series to use in Ubuntu tests.
testedSeriesUbuntu = "precise"

// testedSeriesCentOS is simply the series we use in CentOS tests.
testedSeriesCentOS = "centos7"

// testedSeriesOpenSUSE is simply the series we use in OpenSUSE tests.
testedSeriesOpenSUSE = "opensuseleap"

// testedPackages is a slice of random package tests to run tests on.
testedPackages = []string{
"awesome-wm",
Expand Down
1 change: 0 additions & 1 deletion config/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ var (
CloudArchivePackagesUbuntu = cloudArchivePackagesUbuntu
CloudArchivePackagesCentOS = cloudArchivePackagesCentOS
CloudArchivePackagesOpenSUSE = cloudArchivePackagesOpenSUSE
SeriesRequiringCloudTools = seriesRequiringCloudTools
)
44 changes: 0 additions & 44 deletions config/functions.go

This file was deleted.

81 changes: 0 additions & 81 deletions config/functions_test.go

This file was deleted.

6 changes: 0 additions & 6 deletions config/global_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ function package_manager_loop {
)

var (
seriesRequiringCloudTools = map[string]bool{
// TODO (aznashwan, all): add any other OS's
// which require cloud tools' series here.
"precise": true,
}

// DefaultPackages is a list of the default packages Juju'd like to see
// installed on all it's machines.
DefaultPackages = []string{
Expand Down
30 changes: 10 additions & 20 deletions config/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ type PackagingConfigurer interface {
// installed the vast majority of cases on any specific machine
DefaultPackages() []string

// GetPackageNameForSeries returns the equivalent package name of the
// specified package for the given series or an error if no mapping
// for it exists.
GetPackageNameForSeries(pack string, series string) (string, error)

// IsCloudArchivePackage signals whether the given package is a
// cloud archive package and thus should be set as such.
IsCloudArchivePackage(pack string) bool
Expand All @@ -40,40 +35,35 @@ type PackagingConfigurer interface {
RenderPreferences(prefs packaging.PackagePreferences) (string, error)
}

func NewPackagingConfigurer(series string) (PackagingConfigurer, error) {
switch series {
// TODO (aznashwan): find a more deterministic way of selection here
// without importing version from core.
case "centos7":
return NewYumPackagingConfigurer(series), nil
case "opensuseleap":
return NewZypperPackagingConfigurer(series), nil
func NewPackagingConfigurer(os string) (PackagingConfigurer, error) {
switch os {
case "centos":
return NewYumPackagingConfigurer(), nil
case "opensuse":
return NewZypperPackagingConfigurer(), nil
default:
return NewAptPackagingConfigurer(series), nil
return NewAptPackagingConfigurer(), nil
}
}

// NewAptPackagingConfigurer returns a PackagingConfigurer for apt-based systems.
func NewAptPackagingConfigurer(series string) PackagingConfigurer {
func NewAptPackagingConfigurer() PackagingConfigurer {
return &aptConfigurer{&baseConfigurer{
series: series,
defaultPackages: UbuntuDefaultPackages,
cloudArchivePackages: cloudArchivePackagesUbuntu,
}}
}

// NewYumPackagingConfigurer returns a PackagingConfigurer for yum-based systems.
func NewYumPackagingConfigurer(series string) PackagingConfigurer {
func NewYumPackagingConfigurer() PackagingConfigurer {
return &yumConfigurer{&baseConfigurer{
series: series,
defaultPackages: CentOSDefaultPackages,
cloudArchivePackages: cloudArchivePackagesCentOS,
}}
}

func NewZypperPackagingConfigurer(series string) PackagingConfigurer {
func NewZypperPackagingConfigurer() PackagingConfigurer {
return &zypperConfigurer{&baseConfigurer{
series: series,
defaultPackages: OpenSUSEDefaultPackages,
cloudArchivePackages: cloudArchivePackagesOpenSUSE,
}}
Expand Down
6 changes: 3 additions & 3 deletions config/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import (
"github.com/juju/packaging/v2/config"
)

var _ config.PackagingConfigurer = config.NewAptPackagingConfigurer("some-series")
var _ config.PackagingConfigurer = config.NewYumPackagingConfigurer("some-series")
var _ config.PackagingConfigurer = config.NewZypperPackagingConfigurer("some-series")
var _ config.PackagingConfigurer = config.NewAptPackagingConfigurer()
var _ config.PackagingConfigurer = config.NewYumPackagingConfigurer()
var _ config.PackagingConfigurer = config.NewZypperPackagingConfigurer()
11 changes: 0 additions & 11 deletions config/opensuse_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

package config

import (
"github.com/juju/packaging/v2"
)

const (

// OpenSUSESourcesFile is the default file which lists all core sources
Expand All @@ -30,10 +26,3 @@ var cloudArchivePackagesOpenSUSE = map[string]struct{}{
// OpenSUSE Leap + especially for Juju is to ever occur, please add the relevant
// package listings here.
}

// configureCloudArchiveSourceOpenSUSE is a helper function which returns the
// cloud archive PackageSource and PackagePreferences for the given series for
// OpenSUSE machines.
func configureCloudArchiveSourceOpenSUSE(series string) (packaging.PackageSource, packaging.PackagePreferences) {
return packaging.PackageSource{}, packaging.PackagePreferences{}
}
Loading

0 comments on commit a2c4439

Please sign in to comment.