Merge "Add InventoryRepoName field to config"
This commit is contained in:
commit
4ea1b0e2f0
@ -1,11 +1,14 @@
|
||||
inventoryRepositoryName: ""
|
||||
metadataPath: ""
|
||||
phaseRepositoryName: bar_phase_repo
|
||||
targetPath: bar_target_path
|
||||
|
||||
inventoryRepositoryName: ""
|
||||
metadataPath: ""
|
||||
phaseRepositoryName: baz_phase_repo
|
||||
targetPath: baz_target_path
|
||||
|
||||
inventoryRepositoryName: ""
|
||||
metadataPath: ""
|
||||
phaseRepositoryName: foo_phase_repo
|
||||
targetPath: foo_target_path
|
||||
|
@ -1,3 +1,4 @@
|
||||
inventoryRepositoryName: ""
|
||||
metadataPath: ""
|
||||
phaseRepositoryName: foo_phase_repo
|
||||
targetPath: foo_target_path
|
||||
|
@ -348,7 +348,25 @@ func (c *Config) CurrentContextPhaseRepositoryDir() (string, error) {
|
||||
}
|
||||
repo, exist := ccm.Repositories[ccm.PhaseRepositoryName]
|
||||
if !exist {
|
||||
return "", ErrMissingRepositoryName{}
|
||||
return "", ErrMissingRepositoryName{RepoType: "phase"}
|
||||
}
|
||||
return util.GitDirNameFromURL(repo.URL()), nil
|
||||
}
|
||||
|
||||
// CurrentContextInventoryRepositoryName returns phase inventory directory from current context's manifest
|
||||
// if it is not defined PhaseRepositoryName will be used instead
|
||||
func (c *Config) CurrentContextInventoryRepositoryName() (string, error) {
|
||||
ccm, err := c.CurrentContextManifest()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
repoName := ccm.InventoryRepositoryName
|
||||
if repoName == "" {
|
||||
repoName = ccm.PhaseRepositoryName
|
||||
}
|
||||
repo, exist := ccm.Repositories[repoName]
|
||||
if !exist {
|
||||
return "", ErrMissingRepositoryName{RepoType: "inventory"}
|
||||
}
|
||||
return util.GitDirNameFromURL(repo.URL()), nil
|
||||
}
|
||||
|
@ -336,10 +336,40 @@ func TestCurrentPhaseRepositoryDir(t *testing.T) {
|
||||
conf.Manifests[defaultString].PhaseRepositoryName = "nonexisting"
|
||||
phaseRepoDir, err = conf.CurrentContextPhaseRepositoryDir()
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, config.ErrMissingRepositoryName{}, err)
|
||||
assert.Equal(t, config.ErrMissingRepositoryName{RepoType: "phase"}, err)
|
||||
assert.Equal(t, "", phaseRepoDir)
|
||||
}
|
||||
|
||||
func TestCurrentInventoryRepositoryDir(t *testing.T) {
|
||||
conf, cleanup := testutil.InitConfig(t)
|
||||
defer cleanup(t)
|
||||
|
||||
conf.CurrentContext = currentContextName
|
||||
conf.Contexts[currentContextName].Manifest = defaultString
|
||||
|
||||
invRepoDir, err := conf.CurrentContextInventoryRepositoryName()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, util.GitDirNameFromURL(
|
||||
conf.Manifests[defaultString].Repositories[conf.Manifests[defaultString].PhaseRepositoryName].URL()),
|
||||
invRepoDir)
|
||||
|
||||
conf.Manifests[defaultString].InventoryRepositoryName = "nonexisting"
|
||||
invRepoDir, err = conf.CurrentContextInventoryRepositoryName()
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, config.ErrMissingRepositoryName{RepoType: "inventory"}, err)
|
||||
assert.Equal(t, "", invRepoDir)
|
||||
|
||||
invRepoName := "inv-repo"
|
||||
invRepoURL := "/my-repository"
|
||||
conf.Manifests[defaultString].Repositories[invRepoName] = &config.Repository{URLString: invRepoURL}
|
||||
conf.Manifests[defaultString].InventoryRepositoryName = invRepoName
|
||||
invRepoDir, err = conf.CurrentContextInventoryRepositoryName()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, util.GitDirNameFromURL(
|
||||
conf.Manifests[defaultString].Repositories[conf.Manifests[defaultString].InventoryRepositoryName].URL()),
|
||||
invRepoDir)
|
||||
}
|
||||
|
||||
func TestCurrentContextManifestMetadata(t *testing.T) {
|
||||
expectedMeta := &config.Metadata{
|
||||
Inventory: &config.InventoryMeta{
|
||||
|
@ -83,10 +83,11 @@ func (e ErrRepositoryNotFound) Error() string {
|
||||
// ErrMissingRepositoryName is returned if repository name is empty
|
||||
// when using in set-manifest
|
||||
type ErrMissingRepositoryName struct {
|
||||
RepoType string
|
||||
}
|
||||
|
||||
func (e ErrMissingRepositoryName) Error() string {
|
||||
return "Missing repository name."
|
||||
return fmt.Sprintf("Missing '%s' repository name.", e.RepoType)
|
||||
}
|
||||
|
||||
// ErrMissingRepoURL is returned if repository is empty
|
||||
|
@ -22,6 +22,10 @@ type Manifest struct {
|
||||
// PhaseRepositoryName is a name of the repo, that contains site/<site-name> directory
|
||||
// and is a starting point for building document bundle
|
||||
PhaseRepositoryName string `json:"phaseRepositoryName"`
|
||||
// InventoryRepositoryName is a name of the repo contains inventory objects
|
||||
// to be used mostly with baremetal deployments
|
||||
// If not defined PhaseRepositoryName will be used to locate inventory
|
||||
InventoryRepositoryName string `json:"inventoryRepositoryName"`
|
||||
// ExtraRepositories is the map of extra repositories addressable by a name
|
||||
Repositories map[string]*Repository `json:"repositories,omitempty"`
|
||||
// TargetPath Local Target path for working or home directory for all Manifest Cloned/Returned/Generated
|
||||
|
1
pkg/config/testdata/config-string.yaml
vendored
1
pkg/config/testdata/config-string.yaml
vendored
@ -17,6 +17,7 @@ managementConfiguration:
|
||||
type: redfish
|
||||
manifests:
|
||||
dummy_manifest:
|
||||
inventoryRepositoryName: primary
|
||||
metadataPath: metadata.yaml
|
||||
phaseRepositoryName: primary
|
||||
repositories:
|
||||
|
1
pkg/config/testdata/manifest-string.yaml
vendored
1
pkg/config/testdata/manifest-string.yaml
vendored
@ -1,3 +1,4 @@
|
||||
inventoryRepositoryName: primary
|
||||
metadataPath: metadata.yaml
|
||||
phaseRepositoryName: primary
|
||||
repositories:
|
||||
|
@ -47,9 +47,10 @@ func NewConfig() *Config {
|
||||
},
|
||||
},
|
||||
},
|
||||
TargetPath: "/tmp/" + AirshipDefaultManifest,
|
||||
PhaseRepositoryName: DefaultTestPhaseRepo,
|
||||
MetadataPath: DefaultManifestMetadataFile,
|
||||
TargetPath: "/tmp/" + AirshipDefaultManifest,
|
||||
PhaseRepositoryName: DefaultTestPhaseRepo,
|
||||
InventoryRepositoryName: DefaultTestPhaseRepo,
|
||||
MetadataPath: DefaultManifestMetadataFile,
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -64,10 +65,11 @@ func NewContext() *Context {
|
||||
// object with non-nil maps
|
||||
func NewManifest() *Manifest {
|
||||
return &Manifest{
|
||||
PhaseRepositoryName: DefaultTestPhaseRepo,
|
||||
TargetPath: DefaultTargetPath,
|
||||
Repositories: map[string]*Repository{DefaultTestPhaseRepo: NewRepository()},
|
||||
MetadataPath: DefaultManifestMetadataFile,
|
||||
InventoryRepositoryName: DefaultTestPhaseRepo,
|
||||
PhaseRepositoryName: DefaultTestPhaseRepo,
|
||||
TargetPath: DefaultTargetPath,
|
||||
Repositories: map[string]*Repository{DefaultTestPhaseRepo: NewRepository()},
|
||||
MetadataPath: DefaultManifestMetadataFile,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ func (i Invetnory) BaremetalInventory() (ifc.BaremetalInventory, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
phaseDir, err := cfg.CurrentContextPhaseRepositoryDir()
|
||||
phaseDir, err := cfg.CurrentContextInventoryRepositoryName()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -69,6 +69,7 @@ func TestBaremetalInventory(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
manifest.MetadataPath = "metadata.yaml"
|
||||
manifest.PhaseRepositoryName = "testdata"
|
||||
manifest.InventoryRepositoryName = "testdata"
|
||||
manifest.Repositories["testdata"] = &config.Repository{
|
||||
URLString: "/myrepo/testdata",
|
||||
}
|
||||
@ -87,7 +88,7 @@ func TestBaremetalInventory(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), tt.errString)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, bmhInv)
|
||||
}
|
||||
})
|
||||
|
@ -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.InventoryRepositoryName = "primary"
|
||||
m.MetadataPath = "metadata.yaml"
|
||||
m.TargetPath = "/var/tmp/"
|
||||
return m
|
||||
|
Loading…
Reference in New Issue
Block a user