Ejemplo n.º 1
0
// TestCustomServerAttributes test CustomServerAttributes
func TestCustomServerAttributes(t *testing.T) {
	var testServerAttributes *icsp.CustomServerAttributes
	testServerAttributes = testServerAttributes.New()
	testServerAttributes.Set("ssh_user", "docker")
	log.Infof("testServer -> %+v", testServerAttributes)
	assert.Equal(t, "docker", testServerAttributes.Get("ssh_user"), "should be equal when called for ssh_user")
}
Ejemplo n.º 2
0
// Create - create server for docker
func (d *Driver) Create() error {
	log.Infof("Generating SSH keys...")
	if err := d.createKeyPair(); err != nil {
		return fmt.Errorf("unable to create key pair: %s", err)
	}

	log.Debugf("ICSP Endpoint is: %s", d.ClientICSP.Endpoint)
	log.Debugf("OV Endpoint is: %s", d.ClientOV.Endpoint)
	// create the server profile in oneview, we need a hostname and a template name

	log.Debugf("***> CreateMachine")
	// create d.Hardware and d.Profile
	if err := d.ClientOV.CreateMachine(d.MachineName, d.ServerTemplate); err != nil {
		return err
	}

	if err := d.getBlade(); err != nil {
		return err
	}

	// power off let customization bring the server online
	if err := d.Hardware.PowerOff(); err != nil {
		return err
	}

	// add the server to icsp, TestCreateServer
	// apply a build plan, TestApplyDeploymentJobs
	var sp *icsp.CustomServerAttributes
	sp = sp.New()
	sp.Set("docker_user", d.SSHUser)
	sp.Set("public_key", d.SSHPublicKey)
	// TODO: make a util for this
	if len(os.Getenv("proxy_enable")) > 0 {
		sp.Set("proxy_enable", os.Getenv("proxy_enable"))
	} else {
		sp.Set("proxy_enable", "false")
	}

	strProxy := os.Getenv("proxy_config")
	sp.Set("proxy_config", strProxy)

	sp.Set("docker_hostname", d.MachineName+"-@server_name@")

	sp.Set("interface", "@interface@") // this is populated later

	// Get the mac address for public Connection on server profile
	var publicmac string
	if d.PublicConnectionName != "" {
		conn, err := d.Profile.GetConnectionByName(d.PublicConnectionName)
		if err != nil {
			return err
		}
		publicmac = conn.MAC.String()
	} else {
		publicmac = ""
	}

	// arguments for customize server
	cs := icsp.CustomizeServer{
		HostName:         d.MachineName,                   // machine-rack-enclosure-bay
		SerialNumber:     d.Profile.SerialNumber.String(), // get it
		ILoUser:          d.IloUser,
		IloPassword:      d.IloPassword,
		IloIPAddress:     d.Hardware.GetIloIPAddress(), // MpIpAddress for v1
		IloPort:          d.IloPort,
		OSBuildPlan:      d.OSBuildPlan,  // name of the OS build plan
		PublicSlotID:     d.PublicSlotID, // this is the slot id of the public interface
		PublicMAC:        publicmac,      // Server profile mac address, overrides slotid
		ServerProperties: sp,
	}
	// create d.Server and apply a build plan and configure the custom attributes
	if err := d.ClientICSP.CustomizeServer(cs); err != nil {
		return err
	}

	ip, err := d.GetIP()
	if err != nil {
		return err
	}
	d.IPAddress = ip

	// use ssh to set keys, and test ssh
	sshClient, err := d.getLocalSSHClient()
	if err != nil {
		return err
	}

	pubKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
	if err != nil {
		return err
	}

	if out, err := sshClient.Output(fmt.Sprintf(
		"printf '%%s' '%s' | tee /home/%s/.ssh/authorized_keys",
		string(pubKey),
		d.GetSSHUsername(),
	)); err != nil {
		log.Error(out)
		return err
	}
	log.Infof("%s, Completed all create steps, docker provisioning will continue.", d.DriverName())

	defer closeAll(d)
	return nil
}
// TestCustomizeServer - simulate second part of create
func TestCustomizeServer(t *testing.T) {
	var (
		err                                                 error
		driver                                              Driver
		d                                                   *OneViewTest
		c                                                   *ov.OVClient
		ic                                                  *icsp.ICSPClient
		serialNumber, osbuildplan, hostname, user, pass, ip string
	)
	if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") != "true" {
		return
	}
	if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
		user = os.Getenv("ONEVIEW_ILO_USER")
		pass = os.Getenv("ONEVIEW_ILO_PASSWORD")
		d, c, ic = d.GetTestDriverA()
		if c == nil {
			t.Fatalf("Failed to execute getTestDriver() ")
		}
		ip = d.Tc.GetTestData(d.Env, "IloIPAddress").(string)
		// serialNumber := d.Tc.GetTestData(d.Env, "FreeBladeSerialNumber").(string)
		hostname = d.Tc.GetTestData(d.Env, "HostName").(string)
		driver = Driver{
			ClientICSP: ic,
			ClientOV:   c,
			BaseDriver: &drivers.BaseDriver{
				MachineName: hostname,
				StorePath:   "",
			},
		}
		err = driver.getBlade()
		assert.NoError(t, err, "getBlade threw error -> %s\n", err)
		serialNumber = driver.Profile.SerialNumber.String()

		osbuildplan = d.Tc.GetTestData(d.Env, "OSBuildPlan").(string)

		var sp *icsp.CustomServerAttributes
		sp = sp.New()
		sp.Set("docker_user", "docker")
		// TODO: make a util for this
		if len(os.Getenv("proxy_enable")) > 0 {
			sp.Set("proxy_enable", os.Getenv("proxy_enable"))
		} else {
			sp.Set("proxy_enable", "false")
		}

		strProxy := os.Getenv("proxy_config")
		sp.Set("proxy_config", strProxy)

		sp.Set("docker_hostname", hostname+"-@server_name@")
		// interface
		sp.Set("interface", fmt.Sprintf("eno%d", 50)) // TODO: what argument should we call 50 besides slotid ??

		// check if the server now exist
		cs := icsp.CustomizeServer{
			HostName:         hostname,     // machine-rack-enclosure-bay
			SerialNumber:     serialNumber, // get it
			ILoUser:          user,
			IloPassword:      pass,
			IloIPAddress:     ip,
			IloPort:          443,
			OSBuildPlan:      osbuildplan, // name of the OS build plan
			PublicSlotID:     1,           // this is the slot id of the public interface
			ServerProperties: sp,
		}
		// create d.Server and apply a build plan and configure the custom attributes
		err := ic.CustomizeServer(cs)
		assert.NoError(t, err, "CustomizeServer threw error -> %s\n", err)

	}
}