sshpart_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package sshpart
  15. import (
  16. //"syscall"
  17. "testing"
  18. "yunion.io/x/log"
  19. "yunion.io/x/onecloud/pkg/hostman/guestfs/fsdriver"
  20. "yunion.io/x/onecloud/pkg/hostman/hostdeployer/apis"
  21. )
  22. var defaultSSHClient ISSHClient
  23. func init() {
  24. defaultSSHClient = &sFakeSshClient{}
  25. }
  26. func TestNewSSHPartition(t *testing.T) {
  27. dev := NewSSHPartition(defaultSSHClient, "/dev/sda2", false)
  28. log.Infof("%v", dev.Exists("/", false))
  29. log.Infof("%v", dev.Exists("/etc/", false))
  30. log.Infof("%v", dev.ListDir("/", false))
  31. dev.Mkdir("/tmp/test123", 0777, false)
  32. dev.Chmod("/", 0777, false)
  33. dev.FilePutContents("/tmp/test123/content", "test1234\nhhhh", true, false)
  34. pubkeys := &apis.SSHKeys{
  35. PublicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCz0BLJD+xXYd3AP26uFs42mQSoznPew6gC84P9eUEAJHdkT/8WqTJV0z9M8ZU+8UbuR3iTSbblatrZepPkU2KkvE9ZkFftCIGCWCgvRWFfrDdMF1jwGYtKDg1xVxCmxzTgR+NCuE7HIyDsNL/IKbIVH6QMCxwAIdxHrAT4WdVvkDrD5ihSmIMgnmbCSidok8N7l9zECN54EccV3LGaABumtO5Y7Um7HRm+gdc6esg3HTkIXW402w92zaeHaqm4EGek/FB24WhIcwSErMhXnnHPoAATNzWD+3RQZo2po+95FE/oZw7QO7hG9lWmCDYpJNim+Ix35ftYs1j1S4hray3z lzx@lzx-t470p",
  36. }
  37. err := fsdriver.DeployAuthorizedKeys(dev, "/home/cloudroot", pubkeys, true, false)
  38. if err != nil {
  39. log.Errorf("Deploy keys error: %v", err)
  40. }
  41. }