github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/pkg/client/unikernel_functionality_test.go (about)

     1  package client_test
     2  
     3  import (
     4  	. "github.com/solo-io/unik/pkg/client"
     5  
     6  	"fmt"
     7  	"github.com/sirupsen/logrus"
     8  	"github.com/solo-io/unik/pkg/types"
     9  	"github.com/solo-io/unik/test/helpers"
    10  	. "github.com/onsi/ginkgo"
    11  	"github.com/onsi/ginkgo/extensions/table"
    12  	. "github.com/onsi/gomega"
    13  	"strings"
    14  	"time"
    15  )
    16  
    17  const (
    18  	test_go_app        = "test_go_app"
    19  	test_rump_java_app = "test_rump_java_app"
    20  	test_java_app      = "test_java_app"
    21  	test_jar_app       = "test_jar_app"
    22  	test_nodejs_app    = "test_nodejs_app"
    23  	test_python3_app   = "test_python3_app"
    24  )
    25  
    26  var ipTimeout = time.Second * 180
    27  
    28  var _ = Describe("Unikernel Functionality", func() {
    29  	daemonUrl := "127.0.0.1:3000"
    30  	var c = UnikClient(daemonUrl)
    31  	Describe("instances", func() {
    32  		Describe("All()", func() {
    33  			var image *types.Image
    34  			var volume *types.Volume
    35  			AfterEach(func() {
    36  				if image != nil {
    37  					c.Images().Delete(image.Id, true)
    38  				}
    39  				if volume != nil {
    40  					c.Volumes().Delete(volume.Id, true)
    41  				}
    42  			})
    43  			Context("instances exist", func() {
    44  				Describe("Run()", func() {
    45  					imagesWithVolumes := []string{
    46  						test_go_app,
    47  						test_python3_app,
    48  						test_nodejs_app,
    49  					}
    50  					imagesWithoutVolumes := []string{
    51  						test_java_app,
    52  						test_jar_app,
    53  					}
    54  					providersWithVolumes := []string{}
    55  					//TODO: aws should support mounts
    56  					providersWithoutVolumes := []string{}
    57  					if len(cfg.Providers.Virtualbox) > 0 {
    58  						providersWithVolumes = append(providersWithVolumes, "virtualbox")
    59  					}
    60  					if len(cfg.Providers.Vsphere) > 0 {
    61  						providersWithVolumes = append(providersWithVolumes, "vsphere")
    62  					}
    63  					if len(cfg.Providers.Aws) > 0 {
    64  						providersWithoutVolumes = append(providersWithoutVolumes, "aws")
    65  					}
    66  					if len(cfg.Providers.Xen) > 0 {
    67  						providersWithoutVolumes = append(providersWithoutVolumes, "xen")
    68  					}
    69  					entries := []table.TableEntry{}
    70  					for _, imageName := range imagesWithVolumes {
    71  						for _, provider := range providersWithVolumes {
    72  							entries = append(entries, table.Entry(imageName+" on "+provider, imageName, true, provider))
    73  						}
    74  						for _, provider := range providersWithoutVolumes {
    75  							entries = append(entries, table.Entry(imageName+" on "+provider, imageName, false, provider))
    76  						}
    77  					}
    78  					for _, imageName := range imagesWithoutVolumes {
    79  						for _, provider := range providersWithVolumes {
    80  							entries = append(entries, table.Entry(imageName+" on "+provider, imageName, false, provider))
    81  						}
    82  						for _, provider := range providersWithoutVolumes {
    83  							entries = append(entries, table.Entry(imageName+" on "+provider, imageName, false, provider))
    84  						}
    85  					}
    86  					logrus.WithField("entries", entries).WithField("imageNames", append(imagesWithVolumes, imagesWithoutVolumes...)).WithField("providers", providersWithVolumes).Infof("ENTRIES TO TEST")
    87  					Context("Build() then Run()", func() {
    88  						table.DescribeTable("running images", func(imageName string, withVolume bool, provider string) {
    89  							compiler := ""
    90  							switch {
    91  							case strings.Contains(imageName, "go"):
    92  								logrus.Infof("found image type GO: %s", imageName)
    93  								compiler = fmt.Sprintf("rump-go-%s", provider)
    94  								break
    95  							case strings.Contains(imageName, "nodejs"):
    96  								logrus.Infof("found image type NODE: %s", imageName)
    97  								compiler = fmt.Sprintf("rump-nodejs-%s", provider)
    98  								break
    99  							case strings.Contains(imageName, "python"):
   100  								logrus.Infof("found image type PYTHON: %s", imageName)
   101  								compiler = fmt.Sprintf("rump-python-%s", provider)
   102  								break
   103  							case strings.Contains(imageName, "war"):
   104  								fallthrough
   105  							case strings.Contains(imageName, "jar"):
   106  								fallthrough
   107  							case strings.Contains(imageName, "java"):
   108  								logrus.Infof("found image type JAVA: %s", imageName)
   109  								compiler = fmt.Sprintf("osv-java-%s", provider)
   110  								break
   111  							default:
   112  								logrus.Panic("unknown image name " + imageName)
   113  							}
   114  							//vsphere -> vmware for compilers
   115  							compiler = strings.Replace(compiler, "vsphere", "vmware", -1)
   116  							compiler = strings.Replace(compiler, "aws", "xen", -1)
   117  							mounts := []string{}
   118  							mountPointsToVols := map[string]string{}
   119  							var err error
   120  							if withVolume {
   121  								mounts = append(mounts, "/data")
   122  								volume, err = helpers.CreateTestDataVolume(daemonUrl, "test_volume_"+imageName, provider)
   123  								Expect(err).ToNot(HaveOccurred())
   124  								mountPointsToVols["/data"] = volume.Id
   125  							}
   126  							image, err = helpers.BuildTestImage(daemonUrl, imageName, compiler, provider, mounts)
   127  							Expect(err).ToNot(HaveOccurred())
   128  							instanceName := imageName
   129  							noCleanup := false
   130  							env := map[string]string{"KEY": "VAL"}
   131  							memoryMb := 256
   132  							instance, err := c.Instances().Run(instanceName, image.Name, mountPointsToVols, env, memoryMb, noCleanup, false)
   133  							Expect(err).ToNot(HaveOccurred())
   134  							instanceIp, err := helpers.WaitForIp(daemonUrl, instance.Id, ipTimeout)
   135  							Expect(err).ToNot(HaveOccurred())
   136  							testInstancePing(instanceIp)
   137  							testInstanceEnv(instanceIp)
   138  							if withVolume {
   139  								testInstanceMount(instanceIp)
   140  							}
   141  						}, entries...)
   142  					})
   143  				})
   144  			})
   145  		})
   146  	})
   147  })