Phase docs are targetPath + phaseRepo + phase.DocumentEntrypoint

Change-Id: I1d5ea75d1c19eb4ebaf37b28918ccde771bcef85
Relates-To: #356
This commit is contained in:
Vladimir Kozhukalov 2020-10-07 00:27:23 +03:00
parent 0dc4ab7491
commit dc68640389
18 changed files with 119 additions and 27 deletions

View File

@ -1,2 +1,2 @@
phase:
path: airshipctl/manifests/phases
path: manifests/phases

View File

@ -7,7 +7,7 @@ config:
apiVersion: airshipit.org/v1alpha1
kind: ImageConfiguration
name: isogen
documentEntryPoint: airshipctl/manifests/site/test-site/ephemeral/bootstrap
documentEntryPoint: manifests/site/test-site/ephemeral/bootstrap
---
apiVersion: airshipit.org/v1alpha1
kind: Phase
@ -19,7 +19,7 @@ config:
apiVersion: airshipit.org/v1alpha1
kind: KubernetesApply
name: kubernetes-apply
documentEntryPoint: airshipctl/manifests/site/test-site/ephemeral/initinfra
documentEntryPoint: manifests/site/test-site/ephemeral/initinfra
---
apiVersion: airshipit.org/v1alpha1
kind: Phase
@ -31,7 +31,7 @@ config:
apiVersion: airshipit.org/v1alpha1
kind: KubernetesApply
name: kubernetes-apply
documentEntryPoint: airshipctl/manifests/site/test-site/ephemeral/controlplane
documentEntryPoint: manifests/site/test-site/ephemeral/controlplane
---
apiVersion: airshipit.org/v1alpha1
kind: Phase
@ -44,7 +44,7 @@ config:
apiVersion: airshipit.org/v1alpha1
kind: KubernetesApply
name: kubernetes-apply
documentEntryPoint: airshipctl/manifests/site/test-site/target/initinfra
documentEntryPoint: manifests/site/test-site/target/initinfra
---
apiVersion: airshipit.org/v1alpha1
kind: Phase
@ -57,7 +57,7 @@ config:
apiVersion: airshipit.org/v1alpha1
kind: KubernetesApply
name: kubernetes-apply
documentEntryPoint: airshipctl/manifests/site/test-site/target/workers
documentEntryPoint: manifests/site/test-site/target/workers
---
apiVersion: airshipit.org/v1alpha1
kind: Phase
@ -102,4 +102,4 @@ config:
apiVersion: airshipit.org/v1alpha1
kind: KubernetesApply
name: kubernetes-apply
documentEntryPoint: airshipctl/manifests/site/test-site/target/workload
documentEntryPoint: manifests/site/test-site/target/workload

View File

@ -222,6 +222,7 @@ func makeDefaultHelper(t *testing.T) ifc.Helper {
cfg := config.NewConfig()
cfg.Manifests[config.AirshipDefaultManifest].TargetPath = "./testdata"
cfg.Manifests[config.AirshipDefaultManifest].MetadataPath = "metadata.yaml"
cfg.Manifests[config.AirshipDefaultManifest].Repositories[config.DefaultTestPhaseRepo].URLString = ""
cfg.SetLoadedConfigPath(".")
helper, err := phase.NewHelper(cfg)
require.NoError(t, err)

View File

@ -358,6 +358,20 @@ func (c *Config) CurrentContextTargetPath() (string, error) {
return ccm.TargetPath, nil
}
// CurrentContextPhaseRepositoryDir returns phase repository directory from current context's manifest
// E.g. let repository url be "http://dummy.org/phaserepo.git" then repo directory under targetPath is "phaserepo"
func (c *Config) CurrentContextPhaseRepositoryDir() (string, error) {
ccm, err := c.CurrentContextManifest()
if err != nil {
return "", err
}
repo, exist := ccm.Repositories[ccm.PhaseRepositoryName]
if !exist {
return "", ErrMissingRepositoryName{}
}
return util.GitDirNameFromURL(repo.URL()), nil
}
// CurrentContextClusterType returns cluster type of current context
func (c *Config) CurrentContextClusterType() (string, error) {
context, err := c.GetCurrentContext()
@ -568,12 +582,16 @@ func (c *Config) CurrentContextManifestMetadata() (*Metadata, error) {
if err != nil {
return nil, err
}
phaseRepoDir, err := c.CurrentContextPhaseRepositoryDir()
if err != nil {
return nil, err
}
meta := &Metadata{
// Populate with empty values to avoid nil pointers
Inventory: &InventoryMeta{},
PhaseMeta: &PhaseMeta{},
}
err = util.ReadYAMLFile(filepath.Join(manifest.TargetPath, manifest.MetadataPath), meta)
err = util.ReadYAMLFile(filepath.Join(manifest.TargetPath, phaseRepoDir, manifest.MetadataPath), meta)
if err != nil {
return nil, err
}

View File

@ -20,6 +20,8 @@ import (
"strings"
"testing"
"opendev.org/airship/airshipctl/pkg/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -315,6 +317,26 @@ func TestCurrentTargetPath(t *testing.T) {
assert.Equal(t, conf.Manifests[defaultString].TargetPath, targetPath)
}
func TestCurrentPhaseRepositoryDir(t *testing.T) {
conf, cleanup := testutil.InitConfig(t)
defer cleanup(t)
conf.CurrentContext = currentContextName
conf.Contexts[currentContextName].Manifest = defaultString
phaseRepoDir, err := conf.CurrentContextPhaseRepositoryDir()
require.NoError(t, err)
assert.Equal(t, util.GitDirNameFromURL(
conf.Manifests[defaultString].Repositories[conf.Manifests[defaultString].PhaseRepositoryName].URL()),
phaseRepoDir)
conf.Manifests[defaultString].PhaseRepositoryName = "nonexisting"
phaseRepoDir, err = conf.CurrentContextPhaseRepositoryDir()
require.Error(t, err)
assert.Equal(t, config.ErrMissingRepositoryName{}, err)
assert.Equal(t, "", phaseRepoDir)
}
func TestCurrentContextEntryPoint(t *testing.T) {
conf, cleanup := testutil.InitConfig(t)
defer cleanup(t)
@ -414,9 +436,16 @@ func TestCurrentContextManifestMetadata(t *testing.T) {
context := &config.Context{
Manifest: "testManifest",
}
repos := map[string]*config.Repository{
config.DefaultTestPhaseRepo: {
URLString: "",
},
}
manifest := &config.Manifest{
MetadataPath: tt.metaPath,
TargetPath: "testdata",
PhaseRepositoryName: config.DefaultTestPhaseRepo,
Repositories: repos,
}
conf.Manifests = map[string]*config.Manifest{
"testManifest": manifest,

View File

@ -17,7 +17,7 @@ managementConfiguration:
type: redfish
manifests:
dummy_manifest:
metadataPath: manifests/site/test-site/metadata.yaml
metadataPath: metadata.yaml
phaseRepositoryName: primary
repositories:
primary:

View File

@ -1,4 +1,4 @@
metadataPath: manifests/site/test-site/metadata.yaml
metadataPath: metadata.yaml
phaseRepositoryName: primary
repositories:
primary:

View File

@ -52,6 +52,7 @@ func NewConfig() *Config {
TargetPath: "/tmp/" + AirshipDefaultManifest,
PhaseRepositoryName: DefaultTestPhaseRepo,
SubPath: AirshipDefaultManifestRepo + "/manifests/site",
MetadataPath: DefaultManifestMetadataFile,
},
},
}

View File

@ -231,6 +231,12 @@ func makeDefaultHelper(t *testing.T) ifc.Helper {
"default-manifest": {
MetadataPath: "metadata.yaml",
TargetPath: "testdata",
PhaseRepositoryName: config.DefaultTestPhaseRepo,
Repositories: map[string]*config.Repository{
config.DefaultTestPhaseRepo: {
URLString: "",
},
},
},
},
}

View File

@ -154,7 +154,8 @@ func (p *phase) DocumentRoot() (string, error) {
}
targetPath := p.helper.TargetPath()
return filepath.Join(targetPath, relativePath), nil
phaseRepoDir := p.helper.PhaseRepoDir()
return filepath.Join(targetPath, phaseRepoDir, relativePath), nil
}
// Details returns description of the phase

View File

@ -63,6 +63,12 @@ func TestRunCommand(t *testing.T) {
"manifest": {
MetadataPath: "broken_metadata.yaml",
TargetPath: "testdata",
PhaseRepositoryName: config.DefaultTestPhaseRepo,
Repositories: map[string]*config.Repository{
config.DefaultTestPhaseRepo: {
URLString: "",
},
},
},
}
conf.CurrentContext = "context"
@ -127,6 +133,12 @@ func TestPlanCommand(t *testing.T) {
"manifest": {
MetadataPath: "broken_metadata.yaml",
TargetPath: "testdata",
PhaseRepositoryName: config.DefaultTestPhaseRepo,
Repositories: map[string]*config.Repository{
config.DefaultTestPhaseRepo: {
URLString: "",
},
},
},
}
conf.CurrentContext = "context"

View File

@ -34,7 +34,7 @@ type Helper struct {
phaseRoot string
inventoryRoot string
targetPath string
phaseRepoDir string
metadata *config.Metadata
}
@ -47,12 +47,16 @@ func NewHelper(cfg *config.Config) (ifc.Helper, error) {
if err != nil {
return nil, err
}
helper.phaseRepoDir, err = cfg.CurrentContextPhaseRepositoryDir()
if err != nil {
return nil, err
}
helper.metadata, err = cfg.CurrentContextManifestMetadata()
if err != nil {
return nil, err
}
helper.phaseRoot = filepath.Join(helper.targetPath, helper.metadata.PhaseMeta.Path)
helper.inventoryRoot = filepath.Join(helper.targetPath, helper.metadata.Inventory.Path)
helper.phaseRoot = filepath.Join(helper.targetPath, helper.phaseRepoDir, helper.metadata.PhaseMeta.Path)
helper.inventoryRoot = filepath.Join(helper.targetPath, helper.phaseRepoDir, helper.metadata.Inventory.Path)
return helper, nil
}
@ -197,6 +201,12 @@ func (helper *Helper) TargetPath() string {
return helper.targetPath
}
// PhaseRepoDir returns the last part of the repo url
// E.g. http://dummy.org/reponame.git -> reponame
func (helper *Helper) PhaseRepoDir() string {
return helper.phaseRepoDir
}
// PhaseRoot returns path to document root with phase documents
func (helper *Helper) PhaseRoot() string {
return helper.phaseRoot

View File

@ -449,8 +449,11 @@ manifests:
phaseRepositoryName: primary
targetPath: testdata
metadataPath: valid_site/metadata.yaml
subPath: valid_site`
subPath: valid_site
repositories:
primary:
url: "empty/filename/"
`
conf := &config.Config{}
err := yaml.Unmarshal([]byte(confString), conf)
require.NoError(t, err)

View File

@ -23,6 +23,7 @@ import (
// Helper is a phase helper that provides phases with additional config related information
type Helper interface {
TargetPath() string
PhaseRepoDir() string
WorkDir() (string, error)
Phase(phaseID ID) (*v1alpha1.Phase, error)
Plan() (*v1alpha1.PhasePlan, error)

View File

@ -33,6 +33,12 @@ func TestRender(t *testing.T) {
rs := testutil.DummyConfig()
dummyManifest := rs.Manifests["dummy_manifest"]
dummyManifest.TargetPath = "testdata"
dummyManifest.PhaseRepositoryName = config.DefaultTestPhaseRepo
dummyManifest.Repositories = map[string]*config.Repository{
config.DefaultTestPhaseRepo: {
URLString: "",
},
}
dummyManifest.SubPath = ""
dummyManifest.MetadataPath = "metadata.yaml"
fixturePath := "phase"

View File

@ -56,8 +56,11 @@ func withTestDataPath(path string) Configuration {
if err != nil {
panic(fmt.Sprintf("Unable to initialize management tests. Current Context error %q", err))
}
manifest.TargetPath = fmt.Sprintf("testdata/%s", path)
manifest.TargetPath = "testdata"
manifest.MetadataPath = "metadata.yaml"
dummyRepo := testutil.DummyRepository()
dummyRepo.URLString = fmt.Sprintf("http://dummy.url.com/%s.git", path)
manifest.Repositories = map[string]*config.Repository{manifest.PhaseRepositoryName: dummyRepo}
}
}

View File

@ -69,6 +69,7 @@ func DummyManifest() *config.Manifest {
// Repositories is the map of repository addressable by a name
m.Repositories = map[string]*config.Repository{"primary": DummyRepository()}
m.PhaseRepositoryName = "primary"
m.MetadataPath = "metadata.yaml"
m.TargetPath = "/var/tmp/"
m.SubPath = "manifests/site/test-site"
return m

View File

@ -30,7 +30,7 @@ export REMOTE_PROXY=false
export AIRSHIP_CONFIG_ISO_SERVE_HOST=${HOST:-"localhost"}
export AIRSHIP_CONFIG_ISO_PORT=${SERVE_PORT}
export AIRSHIP_CONFIG_ISO_NAME=${ISO_NAME:-"ubuntu-focal.iso"}
export AIRSHIP_CONFIG_METADATA_PATH=${AIRSHIP_CONFIG_METADATA_PATH:-"airshipctl/manifests/metadata.yaml"}
export AIRSHIP_CONFIG_METADATA_PATH=${AIRSHIP_CONFIG_METADATA_PATH:-"manifests/metadata.yaml"}
export SYSTEM_ACTION_RETRIES=30
export SYSTEM_REBOOT_DELAY=30
export AIRSHIP_CONFIG_PHASE_REPO_BRANCH=${BRANCH:-"master"}