[lxc-devel] [distrobuilder/master] Add mapped architecture to pongo2
monstermunchkin on Github
lxc-bot at linuxcontainers.org
Fri Mar 16 12:38:54 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 309 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180316/701b06f5/attachment.bin>
-------------- next part --------------
From 02b0c9d899398c3550db59b3b0ca466435b7e674 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Fri, 16 Mar 2018 11:09:10 +0100
Subject: [PATCH 1/4] *: Introduce MappedArchitecture field
Resolves #71
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
distrobuilder/main.go | 15 ++++++++-------
image/lxd.go | 18 +-----------------
shared/definition.go | 17 +++++++++--------
3 files changed, 18 insertions(+), 32 deletions(-)
diff --git a/distrobuilder/main.go b/distrobuilder/main.go
index 7a8015e..5ec0f77 100644
--- a/distrobuilder/main.go
+++ b/distrobuilder/main.go
@@ -174,12 +174,6 @@ func (c *cmdGlobal) preRunBuild(cmd *cobra.Command, args []string) error {
return err
}
- // Get the mapped architecture
- arch, err := getMappedArchitecture(c.definition)
- if err != nil {
- return err
- }
-
// Create cache directory if we also plan on creating LXC or LXD images
if cmd.CalledAs() != "build-dir" {
err = os.MkdirAll(c.flagCacheDir, 0755)
@@ -195,7 +189,8 @@ func (c *cmdGlobal) preRunBuild(cmd *cobra.Command, args []string) error {
}
// Download the root filesystem
- err = downloader.Run(*c.definition, c.definition.Image.Release, arch, c.sourceDir)
+ err = downloader.Run(*c.definition, c.definition.Image.Release,
+ c.definition.Image.MappedArchitecture, c.sourceDir)
if err != nil {
return fmt.Errorf("Error while downloading source: %s", err)
}
@@ -319,6 +314,12 @@ func getDefinition(fname string, options []string) (*shared.Definition, error) {
return nil, err
}
+ // Get the mapped architecture
+ def.Image.MappedArchitecture, err = getMappedArchitecture(&def)
+ if err != nil {
+ return nil, err
+ }
+
return &def, nil
}
diff --git a/image/lxd.go b/image/lxd.go
index 18de73a..a818b89 100644
--- a/image/lxd.go
+++ b/image/lxd.go
@@ -7,7 +7,6 @@ import (
"time"
"github.com/lxc/lxd/shared/api"
- "github.com/lxc/lxd/shared/osarch"
"gopkg.in/yaml.v2"
"github.com/lxc/distrobuilder/shared"
@@ -113,24 +112,9 @@ func (l *LXDImage) Build(unified bool, compression string) error {
func (l *LXDImage) createMetadata() error {
var err error
- // Get the arch ID of the provided architecture.
- ID, err := osarch.ArchitectureId(l.definition.Image.Architecture)
- if err != nil {
- return err
- }
-
- // Get the "proper" name of the architecture.
- arch, err := osarch.ArchitectureName(ID)
- if err != nil {
- return err
- }
-
- // Use proper architecture name from now on.
- l.definition.Image.Architecture = arch
-
l.Metadata.Architecture = l.definition.Image.Architecture
l.Metadata.CreationDate = time.Now().UTC().Unix()
- l.Metadata.Properties["architecture"] = l.definition.Image.Architecture
+ l.Metadata.Properties["architecture"] = l.definition.Image.MappedArchitecture
l.Metadata.Properties["os"] = l.definition.Image.Distribution
l.Metadata.Properties["release"] = l.definition.Image.Release
l.Metadata.Properties["variant"] = l.definition.Image.Variant
diff --git a/shared/definition.go b/shared/definition.go
index d2ae010..c0f0e68 100644
--- a/shared/definition.go
+++ b/shared/definition.go
@@ -22,14 +22,15 @@ type DefinitionPackages struct {
// A DefinitionImage represents the image.
type DefinitionImage struct {
- Description string `yaml:"description"`
- Distribution string `yaml:"distribution"`
- Release string `yaml:"release,omitempty"`
- Architecture string `yaml:"architecture,omitempty"`
- Expiry string `yaml:"expiry,omitempty"`
- Variant string `yaml:"variant,omitempty"`
- Name string `yaml:"name,omitempty"`
- Serial string `yaml:"serial,omitempty"`
+ Description string `yaml:"description"`
+ Distribution string `yaml:"distribution"`
+ Release string `yaml:"release,omitempty"`
+ Architecture string `yaml:"architecture,omitempty"`
+ Expiry string `yaml:"expiry,omitempty"`
+ Variant string `yaml:"variant,omitempty"`
+ Name string `yaml:"name,omitempty"`
+ Serial string `yaml:"serial,omitempty"`
+ MappedArchitecture string `yaml:"mapped_architecture,omitempty"`
}
// A DefinitionSource specifies the download type and location
From 0612992b668317e5e3033e0b0edfe25863a2bcfe Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Fri, 16 Mar 2018 12:32:18 +0100
Subject: [PATCH 2/4] *: Move some functions to definition.go
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
distrobuilder/main.go | 61 +++-------------------------
distrobuilder/main_lxc.go | 2 +-
distrobuilder/main_lxd.go | 2 +-
shared/definition.go | 100 +++++++++++++++++++++++++++++++++++-----------
4 files changed, 84 insertions(+), 81 deletions(-)
diff --git a/distrobuilder/main.go b/distrobuilder/main.go
index 5ec0f77..8e20b49 100644
--- a/distrobuilder/main.go
+++ b/distrobuilder/main.go
@@ -62,7 +62,6 @@ import (
"path/filepath"
"strings"
- lxd "github.com/lxc/lxd/shared"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
@@ -204,7 +203,7 @@ func (c *cmdGlobal) preRunBuild(cmd *cobra.Command, args []string) error {
defer exitChroot()
// Run post unpack hook
- for _, hook := range getRunnableActions("post-unpack", c.definition) {
+ for _, hook := range c.definition.GetRunnableActions("post-unpack") {
err := shared.RunScript(hook.Action)
if err != nil {
return fmt.Errorf("Failed to run post-unpack: %s", err)
@@ -213,13 +212,13 @@ func (c *cmdGlobal) preRunBuild(cmd *cobra.Command, args []string) error {
// Install/remove/update packages
err = managePackages(c.definition.Packages,
- getRunnableActions("post-update", c.definition))
+ c.definition.GetRunnableActions("post-update"))
if err != nil {
return fmt.Errorf("Failed to manage packages: %s", err)
}
// Run post packages hook
- for _, hook := range getRunnableActions("post-packages", c.definition) {
+ for _, hook := range c.definition.GetRunnableActions("post-packages") {
err := shared.RunScript(hook.Action)
if err != nil {
return fmt.Errorf("Failed to run post-packages: %s", err)
@@ -306,63 +305,13 @@ func getDefinition(fname string, options []string) (*shared.Definition, error) {
}
// Apply some defaults on top of the provided configuration
- shared.SetDefinitionDefaults(&def)
+ def.SetDefaults()
// Validate the result
- err = shared.ValidateDefinition(def)
- if err != nil {
- return nil, err
- }
-
- // Get the mapped architecture
- def.Image.MappedArchitecture, err = getMappedArchitecture(&def)
+ err = def.Validate()
if err != nil {
return nil, err
}
return &def, nil
}
-
-func getMappedArchitecture(def *shared.Definition) (string, error) {
- var arch string
-
- if def.Mappings.ArchitectureMap != "" {
- // Translate the architecture using the requested map
- var err error
- arch, err = shared.GetArch(def.Mappings.ArchitectureMap, def.Image.Architecture)
- if err != nil {
- return "", fmt.Errorf("Failed to translate the architecture name: %s", err)
- }
- } else if len(def.Mappings.Architectures) > 0 {
- // Translate the architecture using a user specified mapping
- var ok bool
- arch, ok = def.Mappings.Architectures[def.Image.Architecture]
- if !ok {
- // If no mapping exists, it means it doesn't need translating
- arch = def.Image.Architecture
- }
- } else {
- // No map or mappings provided, just go with it as it is
- arch = def.Image.Architecture
- }
-
- return arch, nil
-}
-
-func getRunnableActions(trigger string, definition *shared.Definition) []shared.DefinitionAction {
- out := []shared.DefinitionAction{}
-
- for _, action := range definition.Actions {
- if action.Trigger != trigger {
- continue
- }
-
- if len(action.Releases) > 0 && !lxd.StringInSlice(definition.Image.Release, action.Releases) {
- continue
- }
-
- out = append(out, action)
- }
-
- return out
-}
diff --git a/distrobuilder/main_lxc.go b/distrobuilder/main_lxc.go
index 1ab065b..3885390 100644
--- a/distrobuilder/main_lxc.go
+++ b/distrobuilder/main_lxc.go
@@ -72,7 +72,7 @@ func (c *cmdLXC) run(cmd *cobra.Command, args []string) error {
}
// Run post files hook
- for _, action := range getRunnableActions("post-files", c.global.definition) {
+ for _, action := range c.global.definition.GetRunnableActions("post-files") {
err := shared.RunScript(action.Action)
if err != nil {
exitChroot()
diff --git a/distrobuilder/main_lxd.go b/distrobuilder/main_lxd.go
index 129c669..e9d3d7d 100644
--- a/distrobuilder/main_lxd.go
+++ b/distrobuilder/main_lxd.go
@@ -91,7 +91,7 @@ func (c *cmdLXD) run(cmd *cobra.Command, args []string) error {
}
// Run post files hook
- for _, action := range getRunnableActions("post-files", c.global.definition) {
+ for _, action := range c.global.definition.GetRunnableActions("post-files") {
err := shared.RunScript(action.Action)
if err != nil {
exitChroot()
diff --git a/shared/definition.go b/shared/definition.go
index c0f0e68..809982b 100644
--- a/shared/definition.go
+++ b/shared/definition.go
@@ -8,6 +8,8 @@ import (
"strings"
"time"
+ lxd "github.com/lxc/lxd/shared"
+
"github.com/lxc/lxd/shared"
)
@@ -130,47 +132,47 @@ func (d *Definition) SetValue(key string, value interface{}) error {
return nil
}
-// SetDefinitionDefaults sets some default values for the given Definition.
-func SetDefinitionDefaults(def *Definition) {
+// SetDefaults sets some default values.
+func (d *Definition) SetDefaults() {
// default to local arch
- if def.Image.Architecture == "" {
+ if d.Image.Architecture == "" {
uname, _ := shared.Uname()
- def.Image.Architecture = uname.Machine
+ d.Image.Architecture = uname.Machine
}
// set default expiry of 30 days
- if def.Image.Expiry == "" {
- def.Image.Expiry = "30d"
+ if d.Image.Expiry == "" {
+ d.Image.Expiry = "30d"
}
// Set default serial number
- if def.Image.Serial == "" {
- def.Image.Serial = time.Now().UTC().Format("20060102_1504")
+ if d.Image.Serial == "" {
+ d.Image.Serial = time.Now().UTC().Format("20060102_1504")
}
// Set default variant
- if def.Image.Variant == "" {
- def.Image.Variant = "default"
+ if d.Image.Variant == "" {
+ d.Image.Variant = "default"
}
// Set default keyserver
- if def.Source.Keyserver == "" {
- def.Source.Keyserver = "hkps.pool.sks-keyservers.net"
+ if d.Source.Keyserver == "" {
+ d.Source.Keyserver = "hkps.pool.sks-keyservers.net"
}
// Set default name and description templates
- if def.Image.Name == "" {
- def.Image.Name = "{{ image.distribution }}-{{ image.release }}-{{ image.architecture }}-{{ image.variant }}-{{ image.serial }}"
+ if d.Image.Name == "" {
+ d.Image.Name = "{{ image.distribution }}-{{ image.release }}-{{ image.architecture }}-{{ image.variant }}-{{ image.serial }}"
}
- if def.Image.Description == "" {
- def.Image.Description = "{{ image.distribution|capfirst }} {{ image.release }} {{ image.architecture }}{% if image.variant != \"default\" %} ({{ image.variant }}){% endif %} ({{ image.serial }})"
+ if d.Image.Description == "" {
+ d.Image.Description = "{{ image.distribution|capfirst }} {{ image.release }} {{ image.architecture }}{% if image.variant != \"default\" %} ({{ image.variant }}){% endif %} ({{ image.serial }})"
}
}
-// ValidateDefinition validates the given Definition.
-func ValidateDefinition(def Definition) error {
- if strings.TrimSpace(def.Image.Distribution) == "" {
+// Validate validates the Definition.
+func (d *Definition) Validate() error {
+ if strings.TrimSpace(d.Image.Distribution) == "" {
return errors.New("image.distribution may not be empty")
}
@@ -181,7 +183,7 @@ func ValidateDefinition(def Definition) error {
"debootstrap",
"ubuntu-http",
}
- if !shared.StringInSlice(strings.TrimSpace(def.Source.Downloader), validDownloaders) {
+ if !shared.StringInSlice(strings.TrimSpace(d.Source.Downloader), validDownloaders) {
return fmt.Errorf("source.downloader must be one of %v", validDownloaders)
}
@@ -191,7 +193,7 @@ func ValidateDefinition(def Definition) error {
"yum",
"pacman",
}
- if !shared.StringInSlice(strings.TrimSpace(def.Packages.Manager), validManagers) {
+ if !shared.StringInSlice(strings.TrimSpace(d.Packages.Manager), validManagers) {
return fmt.Errorf("packages.manager must be one of %v", validManagers)
}
@@ -203,7 +205,7 @@ func ValidateDefinition(def Definition) error {
"upstart-tty",
}
- for _, file := range def.Files {
+ for _, file := range d.Files {
if !shared.StringInSlice(strings.TrimSpace(file.Generator), validGenerators) {
return fmt.Errorf("files.*.generator must be one of %v", validGenerators)
}
@@ -215,16 +217,68 @@ func ValidateDefinition(def Definition) error {
"debian",
}
- architectureMap := strings.TrimSpace(def.Mappings.ArchitectureMap)
+ architectureMap := strings.TrimSpace(d.Mappings.ArchitectureMap)
if architectureMap != "" {
if !shared.StringInSlice(architectureMap, validMappings) {
return fmt.Errorf("mappings.architecture_map must be one of %v", validMappings)
}
}
+ var err error
+ d.Image.MappedArchitecture, err = d.getMappedArchitecture()
+ if err != nil {
+ return err
+ }
+
return nil
}
+// GetRunnableActions returns a list of actions depending on the trigger
+// and releases.
+func (d *Definition) GetRunnableActions(trigger string) []DefinitionAction {
+ out := []DefinitionAction{}
+
+ for _, action := range d.Actions {
+ if action.Trigger != trigger {
+ continue
+ }
+
+ if len(action.Releases) > 0 && !lxd.StringInSlice(d.Image.Release, action.Releases) {
+ continue
+ }
+
+ out = append(out, action)
+ }
+
+ return out
+}
+
+func (d *Definition) getMappedArchitecture() (string, error) {
+ var arch string
+
+ if d.Mappings.ArchitectureMap != "" {
+ // Translate the architecture using the requested map
+ var err error
+ arch, err = GetArch(d.Mappings.ArchitectureMap, d.Image.Architecture)
+ if err != nil {
+ return "", fmt.Errorf("Failed to translate the architecture name: %s", err)
+ }
+ } else if len(d.Mappings.Architectures) > 0 {
+ // Translate the architecture using a user specified mapping
+ var ok bool
+ arch, ok = d.Mappings.Architectures[d.Image.Architecture]
+ if !ok {
+ // If no mapping exists, it means it doesn't need translating
+ arch = d.Image.Architecture
+ }
+ } else {
+ // No map or mappings provided, just go with it as it is
+ arch = d.Image.Architecture
+ }
+
+ return arch, nil
+}
+
func getFieldByTag(v reflect.Value, t reflect.Type, tag string) (reflect.Value, error) {
parts := strings.SplitN(tag, ".", 2)
From dd35a5830b356a98fde6104e320a5cba187d6958 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Fri, 16 Mar 2018 12:58:14 +0100
Subject: [PATCH 3/4] sources: Simplify Run command signature
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
distrobuilder/main.go | 3 +--
sources/alpine-http.go | 8 +++++---
sources/archlinux-http.go | 14 +++++++++-----
sources/centos-http.go | 9 ++++++---
sources/debootstrap.go | 11 ++++++-----
sources/source.go | 2 +-
sources/ubuntu-http.go | 13 ++++++++-----
7 files changed, 36 insertions(+), 24 deletions(-)
diff --git a/distrobuilder/main.go b/distrobuilder/main.go
index 8e20b49..26d479c 100644
--- a/distrobuilder/main.go
+++ b/distrobuilder/main.go
@@ -188,8 +188,7 @@ func (c *cmdGlobal) preRunBuild(cmd *cobra.Command, args []string) error {
}
// Download the root filesystem
- err = downloader.Run(*c.definition, c.definition.Image.Release,
- c.definition.Image.MappedArchitecture, c.sourceDir)
+ err = downloader.Run(*c.definition, c.sourceDir)
if err != nil {
return fmt.Errorf("Error while downloading source: %s", err)
}
diff --git a/sources/alpine-http.go b/sources/alpine-http.go
index a9f2c3d..e52354c 100644
--- a/sources/alpine-http.go
+++ b/sources/alpine-http.go
@@ -22,10 +22,12 @@ func NewAlpineLinuxHTTP() *AlpineLinuxHTTP {
}
// Run downloads an Alpine Linux mini root filesystem.
-func (s *AlpineLinuxHTTP) Run(definition shared.Definition, release, arch, rootfsDir string) error {
- fname := fmt.Sprintf("alpine-minirootfs-%s-%s.tar.gz", release, arch)
+func (s *AlpineLinuxHTTP) Run(definition shared.Definition, rootfsDir string) error {
+ fname := fmt.Sprintf("alpine-minirootfs-%s-%s.tar.gz", definition.Image.Release,
+ definition.Image.MappedArchitecture)
tarball := fmt.Sprintf("%s/v%s/releases/%s/%s", definition.Source.URL,
- strings.Join(strings.Split(release, ".")[0:2], "."), arch, fname)
+ strings.Join(strings.Split(definition.Image.Release, ".")[0:2], "."),
+ definition.Image.MappedArchitecture, fname)
url, err := url.Parse(tarball)
if err != nil {
diff --git a/sources/archlinux-http.go b/sources/archlinux-http.go
index 33c4cbf..df96cea 100644
--- a/sources/archlinux-http.go
+++ b/sources/archlinux-http.go
@@ -22,9 +22,11 @@ func NewArchLinuxHTTP() *ArchLinuxHTTP {
}
// Run downloads an Arch Linux tarball.
-func (s *ArchLinuxHTTP) Run(definition shared.Definition, release, arch, rootfsDir string) error {
- fname := fmt.Sprintf("archlinux-bootstrap-%s-x86_64.tar.gz", release)
- tarball := fmt.Sprintf("%s/%s/%s", definition.Source.URL, release, fname)
+func (s *ArchLinuxHTTP) Run(definition shared.Definition, rootfsDir string) error {
+ fname := fmt.Sprintf("archlinux-bootstrap-%s-%s.tar.gz",
+ definition.Image.Release, definition.Image.MappedArchitecture)
+ tarball := fmt.Sprintf("%s/%s/%s", definition.Source.URL,
+ definition.Image.Release, fname)
url, err := url.Parse(tarball)
if err != nil {
@@ -65,7 +67,8 @@ func (s *ArchLinuxHTTP) Run(definition shared.Definition, release, arch, rootfsD
// Move everything inside 'root.x86_64' (which was is the tarball) to its
// parent directory
- files, err := filepath.Glob(fmt.Sprintf("%s/*", filepath.Join(rootfsDir, "root.x86_64")))
+ files, err := filepath.Glob(fmt.Sprintf("%s/*", filepath.Join(rootfsDir,
+ "root", definition.Image.MappedArchitecture)))
if err != nil {
return err
}
@@ -77,5 +80,6 @@ func (s *ArchLinuxHTTP) Run(definition shared.Definition, release, arch, rootfsD
}
}
- return os.RemoveAll(filepath.Join(rootfsDir, "root.x86_64"))
+ return os.RemoveAll(filepath.Join(rootfsDir, "root",
+ definition.Image.MappedArchitecture))
}
diff --git a/sources/centos-http.go b/sources/centos-http.go
index 1065f68..9c3f7c3 100644
--- a/sources/centos-http.go
+++ b/sources/centos-http.go
@@ -27,10 +27,13 @@ func NewCentOSHTTP() *CentOSHTTP {
}
// Run downloads the tarball and unpacks it.
-func (s *CentOSHTTP) Run(definition shared.Definition, release, arch, rootfsDir string) error {
- baseURL := fmt.Sprintf("%s/%s/isos/%s/", definition.Source.URL, strings.Split(release, ".")[0], arch)
+func (s *CentOSHTTP) Run(definition shared.Definition, rootfsDir string) error {
+ baseURL := fmt.Sprintf("%s/%s/isos/%s/", definition.Source.URL,
+ strings.Split(definition.Image.Release, ".")[0],
+ definition.Image.MappedArchitecture)
- s.fname = getRelease(definition.Source.URL, release, definition.Source.Variant, arch)
+ s.fname = getRelease(definition.Source.URL, definition.Image.Release,
+ definition.Source.Variant, definition.Image.MappedArchitecture)
if s.fname == "" {
return fmt.Errorf("Couldn't get name of iso")
}
diff --git a/sources/debootstrap.go b/sources/debootstrap.go
index 9cf188f..468bda0 100644
--- a/sources/debootstrap.go
+++ b/sources/debootstrap.go
@@ -18,7 +18,7 @@ func NewDebootstrap() *Debootstrap {
}
// Run runs debootstrap.
-func (s *Debootstrap) Run(definition shared.Definition, release, arch, rootfsDir string) error {
+func (s *Debootstrap) Run(definition shared.Definition, rootfsDir string) error {
var args []string
os.RemoveAll(rootfsDir)
@@ -27,8 +27,8 @@ func (s *Debootstrap) Run(definition shared.Definition, release, arch, rootfsDir
args = append(args, "--variant", definition.Source.Variant)
}
- if arch != "" {
- args = append(args, "--arch", arch)
+ if definition.Image.MappedArchitecture != "" {
+ args = append(args, "--arch", definition.Image.MappedArchitecture)
}
if len(definition.Source.Keys) > 0 {
@@ -41,7 +41,7 @@ func (s *Debootstrap) Run(definition shared.Definition, release, arch, rootfsDir
args = append(args, "--keyring", keyring)
}
- args = append(args, release, rootfsDir)
+ args = append(args, definition.Image.Release, rootfsDir)
if definition.Source.URL != "" {
args = append(args, definition.Source.URL)
@@ -50,7 +50,8 @@ func (s *Debootstrap) Run(definition shared.Definition, release, arch, rootfsDir
// If definition.Source.Suite is set, create a symlink in /usr/share/debootstrap/scripts
// pointing release to definition.Source.Suite.
if definition.Source.Suite != "" {
- link := filepath.Join("/usr/share/debootstrap/scripts", release)
+ link := filepath.Join("/usr/share/debootstrap/scripts",
+ definition.Image.Release)
err := os.Symlink(definition.Source.Suite, link)
if err != nil {
return err
diff --git a/sources/source.go b/sources/source.go
index bd57943..ccdc686 100644
--- a/sources/source.go
+++ b/sources/source.go
@@ -4,7 +4,7 @@ import "github.com/lxc/distrobuilder/shared"
// A Downloader represents a source downloader.
type Downloader interface {
- Run(shared.Definition, string, string, string) error
+ Run(shared.Definition, string) error
}
// Get returns a Downloader.
diff --git a/sources/ubuntu-http.go b/sources/ubuntu-http.go
index 65a2f2b..14cb6e2 100644
--- a/sources/ubuntu-http.go
+++ b/sources/ubuntu-http.go
@@ -28,14 +28,17 @@ func NewUbuntuHTTP() *UbuntuHTTP {
}
// Run downloads the tarball and unpacks it.
-func (s *UbuntuHTTP) Run(definition shared.Definition, release, arch, rootfsDir string) error {
- baseURL := fmt.Sprintf("%s/releases/%s/release/", definition.Source.URL, release)
+func (s *UbuntuHTTP) Run(definition shared.Definition, rootfsDir string) error {
+ baseURL := fmt.Sprintf("%s/releases/%s/release/", definition.Source.URL,
+ definition.Image.Release)
- if strings.ContainsAny(release, "0123456789") {
- s.fname = fmt.Sprintf("ubuntu-base-%s-base-%s.tar.gz", release, arch)
+ if strings.ContainsAny(definition.Image.Release, "0123456789") {
+ s.fname = fmt.Sprintf("ubuntu-base-%s-base-%s.tar.gz",
+ definition.Image.Release, definition.Image.MappedArchitecture)
} else {
// if release is non-numerical, find the latest release
- s.fname = getLatestRelease(definition.Source.URL, release, arch)
+ s.fname = getLatestRelease(definition.Source.URL,
+ definition.Image.Release, definition.Image.MappedArchitecture)
if s.fname == "" {
return fmt.Errorf("Couldn't find latest release")
}
From 02148a5918fafd8eac4f71b8a83321cc43feb480 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Fri, 16 Mar 2018 13:35:04 +0100
Subject: [PATCH 4/4] tests: Fix tests
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
image/lxd_test.go | 16 +++++++++++++++-
shared/definition_test.go | 5 +++--
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/image/lxd_test.go b/image/lxd_test.go
index 3f1b50c..f6d03da 100644
--- a/image/lxd_test.go
+++ b/image/lxd_test.go
@@ -19,11 +19,17 @@ var lxdDef = shared.Definition{
Description: "{{ image.distribution|capfirst }} {{ image. release }}",
Distribution: "ubuntu",
Release: "17.10",
- Architecture: "amd64",
+ Architecture: "x86_64",
Expiry: "30d",
Name: "{{ image.distribution|lower }}-{{ image.release }}-{{ image.architecture }}-{{ image.serial }}",
Serial: "testing",
},
+ Source: shared.DefinitionSource{
+ Downloader: "debootstrap",
+ },
+ Packages: shared.DefinitionPackages{
+ Manager: "apt",
+ },
}
func setupLXD(t *testing.T) *LXDImage {
@@ -52,6 +58,14 @@ func setupLXD(t *testing.T) *LXDImage {
t.Fatal("lxdDef and image.definition are not equal")
}
+ lxdDef.SetDefaults()
+
+ err = lxdDef.Validate()
+ if err != nil {
+ teardownLXD(t)
+ t.Fatalf("Failed to validate image: %s", err)
+ }
+
return image
}
diff --git a/shared/definition_test.go b/shared/definition_test.go
index 75e9506..a236d02 100644
--- a/shared/definition_test.go
+++ b/shared/definition_test.go
@@ -11,7 +11,7 @@ import (
func TestSetDefinitionDefaults(t *testing.T) {
def := Definition{}
- SetDefinitionDefaults(&def)
+ def.SetDefaults()
uname, _ := shared.Uname()
@@ -187,7 +187,8 @@ func TestValidateDefinition(t *testing.T) {
for i, tt := range tests {
log.Printf("Running test #%d: %s", i, tt.name)
- err := ValidateDefinition(tt.definition)
+ tt.definition.SetDefaults()
+ err := tt.definition.Validate()
if !tt.shouldFail && err != nil {
t.Fatalf("Validation failed: %s", err)
} else if tt.shouldFail {
More information about the lxc-devel
mailing list