| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- // Copyright 2019 Yunion
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package disktool
- import "testing"
- // TODO: use mock ssh server backend test disktool
- /*
- import (
- "testing"
- "yunion.io/x/log"
- "yunion.io/x/pkg/util/stringutils"
- "yunion.io/x/onecloud/pkg/compute/baremetal"
- "yunion.io/x/onecloud/pkg/util/ssh"
- )
- var (
- term *ssh.Client
- )
- func init() {
- var err error
- term, err = ssh.NewClient("192.168.0.254", 22, "root", "rMw2qrm6Lb5NVpe0", "")
- if err != nil {
- log.Fatalf("Failed to init ssh client: %v", err)
- }
- }
- func TestSSHCreate(t *testing.T) {
- tool := NewSSHPartitionTool(term)
- err := tool.FetchDiskConfs([]baremetal.DiskConfiguration{
- {
- Adapter: 0,
- Driver: baremetal.DISK_DRIVER_LINUX,
- },
- }).RetrieveDiskInfo()
- if err != nil {
- t.Errorf("Failed to RetrieveDiskInfo: %v", err)
- }
- err = tool.RetrievePartitionInfo()
- if err != nil {
- t.Errorf("Failed to RetrievePartitionInfo: %v", err)
- }
- log.Infof("%s", tool.DebugString())
- uuid := stringutils.UUID4
- tool.CreatePartition(-1, 32, "swap", true, baremetal.DISK_DRIVER_LINUX, uuid())
- tool.CreatePartition(-1, 1024, "ext4", true, baremetal.DISK_DRIVER_LINUX, uuid())
- err = tool.CreatePartition(-1, -1, "xfs", true, baremetal.DISK_DRIVER_LINUX, uuid())
- //err = tool.ResizePartition(0, 110*1024)
- if err != nil {
- t.Errorf("Failed to resize fs: %v", err)
- }
- }*/
- func Test_getPCIPathPrefix(t *testing.T) {
- tests := []struct {
- input string
- want string
- }{
- {
- input: "/sys/devices/pci0000:00/0000:00:02.2/0000:02:00.0/host0/target0:1:0/0:1:0:0/block/sda",
- want: "/sys/devices/pci0000:00/0000:00:02.2/0000:02:00.0/host0/target0:1:0/0:1:0:0",
- },
- {
- input: "/sys/devices/pci0000:00/0000:00:06.0/0000:02:00.0/nvme/nvme0/nvme0n1",
- want: "/sys/devices/pci0000:00/0000:00:06.0/0000:02:00.0/nvme",
- },
- }
- for _, tt := range tests {
- t.Run(tt.input, func(t *testing.T) {
- if got := getPCIPathPrefix(tt.input); got != tt.want {
- t.Errorf("getPCIPathPrefix() = %v, want %v", got, tt.want)
- }
- })
- }
- }
|