f-50: lab: scénarios E5, configuration de l'agent par hyperviseur, release 0.2.0rc003 #50
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
f9aadc00fc
commit
b4660c95d3
25 changed files with 760 additions and 27 deletions
|
|
@ -31,6 +31,7 @@ type Options struct {
|
|||
RunDir string
|
||||
AuthorizedKeys []string
|
||||
FRR map[string]string
|
||||
Agent map[string]string
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
|
|
@ -50,6 +51,9 @@ func Render(p *topology.Plan, o Options) ([]Node, error) {
|
|||
if _, ok := o.FRR[n.Name]; n.FRR != "" && !ok {
|
||||
return nil, fmt.Errorf("node %s: frr configuration %s was not read", n.Name, n.FRR)
|
||||
}
|
||||
if _, ok := o.Agent[n.Name]; n.Agent != "" && !ok {
|
||||
return nil, fmt.Errorf("node %s: agent configuration %s was not read", n.Name, n.Agent)
|
||||
}
|
||||
}
|
||||
var nodes []Node
|
||||
for index, n := range p.Nodes {
|
||||
|
|
|
|||
|
|
@ -262,3 +262,37 @@ func TestRoles_SwitchLoopbackIsCreatedByTheSwitchScript(t *testing.T) {
|
|||
t.Errorf("lab-switch:\n%s\ndoes not end with:\n%s", script, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRoles_HypervisorAgentConfigIsWrittenBeforeTheDeployment(t *testing.T) {
|
||||
doc := strings.Replace(withRoles, "frr: hv1.conf, release: 0.2.0rc002 }", "frr: hv1.conf, release: 0.2.0rc002, agent: two.yml }", 1)
|
||||
nodes, err := Render(plan(t, doc), Options{RunDir: "/srv/lab", AuthorizedKeys: []string{labKey}, FRR: frrConfigs, Agent: map[string]string{"hv1": "dhcp:\n backend: two\n"}})
|
||||
if err != nil {
|
||||
t.Fatalf("Render: %v", err)
|
||||
}
|
||||
var hv1, hv2 Node
|
||||
for _, n := range nodes {
|
||||
switch n.Name {
|
||||
case "hv1":
|
||||
hv1 = n
|
||||
case "hv2":
|
||||
hv2 = n
|
||||
}
|
||||
}
|
||||
f := fileAt(t, user(t, hv1), "/etc/two/agent.yml")
|
||||
if f.Content != "dhcp:\n backend: two\n" || f.Permissions != "0640" {
|
||||
t.Errorf("agent.yml (%s) = %q", f.Permissions, f.Content)
|
||||
}
|
||||
for _, w := range user(t, hv2).WriteFiles {
|
||||
if w.Path == "/etc/two/agent.yml" {
|
||||
t.Error("hv2 receives an agent.yml it does not declare")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRoles_RefusesAnUnreadAgentConfig(t *testing.T) {
|
||||
doc := strings.Replace(withRoles, "frr: hv1.conf, release: 0.2.0rc002 }", "frr: hv1.conf, release: 0.2.0rc002, agent: two.yml }", 1)
|
||||
_, err := Render(plan(t, doc), Options{RunDir: "/srv/lab", AuthorizedKeys: []string{labKey}, FRR: frrConfigs})
|
||||
if err == nil || err.Error() != "node hv1: agent configuration two.yml was not read" {
|
||||
t.Errorf("error = %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ const (
|
|||
DeployScript = "/usr/local/sbin/lab-deploy"
|
||||
TwoScriptsDir = "/opt/two/scripts"
|
||||
TwoGitServer = "https://git.g3e.fr/"
|
||||
AgentConfig = "/etc/two/agent.yml"
|
||||
)
|
||||
|
||||
//go:embed frrouting.gpg
|
||||
|
|
@ -114,6 +115,9 @@ func userData(p *topology.Plan, n topology.NodePlan, o Options) ([]byte, error)
|
|||
}
|
||||
steps = append(steps, "systemctl daemon-reload", "systemctl enable --now lab-node.service")
|
||||
}
|
||||
if n.Agent != "" {
|
||||
cfg.WriteFiles = append(cfg.WriteFiles, writeFile{Path: AgentConfig, Permissions: "0640", Content: o.Agent[n.Name]})
|
||||
}
|
||||
if n.Role == topology.RoleHypervisor {
|
||||
cfg.WriteFiles = append(cfg.WriteFiles,
|
||||
writeFile{Path: TwoScriptsDir + "/deploy.sh", Permissions: "0755", Encoding: "b64", Content: base64.StdEncoding.EncodeToString(scripts.Deploy)},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue