diff --git a/pkg/configmanager/asset/infraasset/infraasset_test.go b/pkg/configmanager/asset/infraasset/infraasset_test.go new file mode 100644 index 0000000000000000000000000000000000000000..65e61770443d524b106b8e3d657802f690f64f55 --- /dev/null +++ b/pkg/configmanager/asset/infraasset/infraasset_test.go @@ -0,0 +1,101 @@ +/* +Copyright 2024 KylinSoft Co., Ltd. + +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 infraasset + +import ( + "nestos-kubernetes-deployer/cmd/command/opts" + "nestos-kubernetes-deployer/pkg/configmanager/asset" + "testing" +) + +func TestInfra(t *testing.T) { + opts := &opts.OptionsList{ + RootOptDir: "/tmp", + InfraPlatform: opts.InfraPlatform{ + Libvirt: opts.Libvirt{ + URI: "qemu:///system", + OSPath: "/etc/qcow2.qcow2", + CIDR: "192.168.132.0/24", + Gateway: "192.168.132.1", + }, + }, + } + + cc := &asset.ClusterAsset{ + ClusterID: "cluster", + Architecture: "amd64", + Platform: "libvirt", + OSImage: asset.OSImage{Type: "nestos"}, + UserName: "root", + Password: "123", + SSHKey: "./assets.go", + Master: []asset.NodeAsset{ + { + Hostname: "k8s-master01", + IP: "192.168.132.11", + HardwareInfo: asset.HardwareInfo{ + CPU: 2, + RAM: 2048, + Disk: 30, + }, + }, + }, + Worker: []asset.NodeAsset{ + { + Hostname: "k8s-worker01", + IP: "192.168.132.12", + HardwareInfo: asset.HardwareInfo{ + CPU: 2, + RAM: 2048, + Disk: 30, + }, + }, + }, + Runtime: "crio", + Kubernetes: asset.Kubernetes{ + KubernetesVersion: "v1.29.1", + KubernetesAPIVersion: "v1beta3", + ApiServerEndpoint: "192.168.132.11:6443", + ImageRegistry: "registry.k8s.io", + PauseImage: "pause:3.9", + Network: asset.Network{ + ServiceSubnet: "10.96.0.0/16", + PodSubnet: "10.244.0.0/16", + }, + }, + HookConf: asset.HookConf{ + ShellFiles: []asset.ShellFile{ + {Name: "sss"}, + {Name: "sss"}, + }, + }, + } + + t.Run("InitInfraAsset Success", func(t *testing.T) { + _, err := InitInfraAsset(cc, opts) + if err != nil { + t.Errorf("InitInfraAsset failed: %v", err) + } + }) + + t.Run("InitInfraAsset Fail", func(t *testing.T) { + cc.Platform = "test" + _, err := InitInfraAsset(cc, opts) + if err == nil { + t.Error("Expected error, got nil") + } + }) +} diff --git a/pkg/configmanager/asset/infraasset/ipxeasset_test.go b/pkg/configmanager/asset/infraasset/ipxeasset_test.go new file mode 100644 index 0000000000000000000000000000000000000000..73b0a59f6c1a622c17e9bbdbdf8294feeb6cd17f --- /dev/null +++ b/pkg/configmanager/asset/infraasset/ipxeasset_test.go @@ -0,0 +1,53 @@ +/* +Copyright 2024 KylinSoft Co., Ltd. + +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 infraasset + +import ( + "nestos-kubernetes-deployer/cmd/command/opts" + "testing" +) + +func TestIPXE(t *testing.T) { + opts := &opts.OptionsList{ + RootOptDir: "/tmp", + InfraPlatform: opts.InfraPlatform{ + IPXE: opts.IPXE{ + IP: "127.0.0.1", + Port: "666", + FilePath: "/tmp", + OSInstallTreePath: "/tmp", + }, + }, + } + + la := IPXEAsset{} + + t.Run("InitAsset Success", func(t *testing.T) { + _, err := la.InitAsset(nil, opts, nil) + if err != nil { + t.Errorf("InitAsset failed: %v", err) + } + }) + + t.Run("InitAsset Fail", func(t *testing.T) { + la.FilePath = "" + opts.InfraPlatform.IPXE.FilePath = "" + _, err := la.InitAsset(nil, opts, nil) + if err == nil { + t.Error("Expected error, got nil") + } + }) +} diff --git a/pkg/configmanager/asset/infraasset/libvirtasset_test.go b/pkg/configmanager/asset/infraasset/libvirtasset_test.go new file mode 100644 index 0000000000000000000000000000000000000000..91c3ac5a51ee52ae28d12f2b4f0b56efcd45ce93 --- /dev/null +++ b/pkg/configmanager/asset/infraasset/libvirtasset_test.go @@ -0,0 +1,53 @@ +/* +Copyright 2024 KylinSoft Co., Ltd. + +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 infraasset + +import ( + "nestos-kubernetes-deployer/cmd/command/opts" + "testing" +) + +func TestLibvirt(t *testing.T) { + opts := &opts.OptionsList{ + RootOptDir: "/tmp", + InfraPlatform: opts.InfraPlatform{ + Libvirt: opts.Libvirt{ + URI: "qemu:///system", + OSPath: "/etc/qcow2.qcow2", + CIDR: "192.168.132.0/24", + Gateway: "192.168.132.1", + }, + }, + } + + la := LibvirtAsset{} + + t.Run("InitAsset Success", func(t *testing.T) { + _, err := la.InitAsset(nil, opts, nil) + if err != nil { + t.Errorf("InitAsset failed: %v", err) + } + }) + + t.Run("InitAsset Fail", func(t *testing.T) { + la.OSPath = "" + opts.InfraPlatform.Libvirt.OSPath = "" + _, err := la.InitAsset(nil, opts, nil) + if err == nil { + t.Error("Expected error, got nil") + } + }) +} diff --git a/pkg/configmanager/asset/infraasset/openstackasset_test.go b/pkg/configmanager/asset/infraasset/openstackasset_test.go new file mode 100644 index 0000000000000000000000000000000000000000..a8b4372147e46d8d5a5e33f04ed57c081f540070 --- /dev/null +++ b/pkg/configmanager/asset/infraasset/openstackasset_test.go @@ -0,0 +1,57 @@ +/* +Copyright 2024 KylinSoft Co., Ltd. + +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 infraasset + +import ( + "nestos-kubernetes-deployer/cmd/command/opts" + "testing" +) + +func TestOpenstack(t *testing.T) { + opts := &opts.OptionsList{ + RootOptDir: "/tmp", + InfraPlatform: opts.InfraPlatform{ + OpenStack: opts.OpenStack{ + UserName: "admin", + Password: "", + TenantName: "admin", + AuthURL: "http://controller:5000/v3", + Region: "RegionOne", + InternalNetwork: "internal-net", + ExternalNetwork: "provider-flat-net", + GlanceName: "nestos.qcow2", + AvailabilityZone: "Phytium", + }, + }, + } + + oa := OpenStackAsset{} + + t.Run("InitAsset Fail", func(t *testing.T) { + _, err := oa.InitAsset(nil, opts, nil) + if err == nil { + t.Error("Expected error, got nil") + } + }) + + opts.InfraPlatform.OpenStack.Password = "123456" + t.Run("InitAsset Success", func(t *testing.T) { + _, err := oa.InitAsset(nil, opts, nil) + if err != nil { + t.Errorf("InitAsset failed: %v", err) + } + }) +} diff --git a/pkg/configmanager/asset/infraasset/pxeasset_test.go b/pkg/configmanager/asset/infraasset/pxeasset_test.go new file mode 100644 index 0000000000000000000000000000000000000000..d09e53d5c4b4b814f6c12fbf8c0f31d6f12c2424 --- /dev/null +++ b/pkg/configmanager/asset/infraasset/pxeasset_test.go @@ -0,0 +1,52 @@ +/* +Copyright 2024 KylinSoft Co., Ltd. + +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 infraasset + +import ( + "nestos-kubernetes-deployer/cmd/command/opts" + "testing" +) + +func TestPXE(t *testing.T) { + opts := &opts.OptionsList{ + RootOptDir: "/tmp", + InfraPlatform: opts.InfraPlatform{ + PXE: opts.PXE{ + IP: "", + HTTPServerPort: "10", + HTTPRootDir: "./", + TFTPServerPort: "20", + TFTPRootDir: "./", + }, + }, + } + pa := PXEAsset{} + + t.Run("InitAsset Fail", func(t *testing.T) { + _, err := pa.InitAsset(nil, opts, nil) + if err == nil { + t.Error("Expected error, got nil") + } + }) + + opts.InfraPlatform.PXE.IP = "127.0.0.1" + t.Run("InitAsset Success", func(t *testing.T) { + _, err := pa.InitAsset(nil, opts, nil) + if err != nil { + t.Errorf("InitAsset failed: %v", err) + } + }) +}