PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/condor-cloud-0.1/tests/instances_test.rb

#
Ruby | 84 lines | 57 code | 9 blank | 18 comment | 0 complexity | 3be0d4198f5573b6ff4b5b8fcf982426 MD5 | raw file
Possible License(s): Apache-2.0
  1. #
  2. # Copyright (C) 2011 Red Hat, Inc.
  3. #
  4. # Licensed to the Apache Software Foundation (ASF) under one or more
  5. # contributor license agreements. See the NOTICE file distributed with
  6. # this work for additional information regarding copyright ownership. The
  7. # ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance with the
  9. # License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. # License for the specific language governing permissions and limitations
  17. # under the License.
  18. #
  19. require 'tests/common'
  20. class TestCondorInstances < Test::Unit::TestCase
  21. def setup
  22. @condor = CondorCloud::DefaultExecutor
  23. end
  24. def test_list_of_instances
  25. @condor.new do |c|
  26. assert_instance_of(Array, c.instances)
  27. assert_equal(1, c.instances.size)
  28. assert_instance_of(CondorCloud::Instance, c.instances.first)
  29. assert_instance_of(CondorCloud::Realm, c.instances.first.realm)
  30. end
  31. end
  32. def test_first_instance_image
  33. @condor.new do |c|
  34. assert_instance_of(CondorCloud::Image, c.instances.first.image)
  35. assert_equal('7de6086a9e6ff76dd8bd37c9e770ab4f5cb4649a', c.instances.first.image.id)
  36. assert_equal('fedora_work_machine-clone-img', c.instances.first.image.name)
  37. end
  38. end
  39. def test_first_instance_attributes
  40. @condor.new do |c|
  41. assert_equal('1300202231', c.instances.first.id)
  42. assert_equal('kvm_test2', c.instances.first.name)
  43. assert_instance_of(CondorCloud::HardwareProfile, c.instances.first.instance_profile)
  44. assert_equal('RUNNING', c.instances.first.state)
  45. assert_instance_of(CondorCloud::Address, c.instances.first.public_addresses.first)
  46. assert_equal('', c.instances.first.public_addresses.first.ip)
  47. assert_equal('52:54:00:ab:90:41', c.instances.first.public_addresses.first.mac)
  48. end
  49. end
  50. def test_filtering_instances_by_id
  51. @condor.new do |c|
  52. assert_instance_of(Array, c.instances(:id => '1300202231'))
  53. assert_equal(1, c.instances(:id => '1300202231').size)
  54. assert_equal(0, c.instances(:id => '---- TEST ----').size)
  55. end
  56. end
  57. def test_launch_instance
  58. @image = CondorCloud::Image.new(:name => 'Fedora14EmptyImage.img', :description => 'tests/images/Fedora14EmptyImage.img')
  59. @hardware_profile = CondorCloud::HardwareProfile.new(:name => 'medium')
  60. @condor.new do |c|
  61. instance = c.launch_instance(@image, @hardware_profile, :name => 'kvm_test2')
  62. assert_instance_of(Array, instance)
  63. assert_instance_of(CondorCloud::Instance, instance.first)
  64. assert_instance_of(CondorCloud::HardwareProfile, instance.first.instance_profile)
  65. assert_equal('medium', instance.first.instance_profile.name)
  66. assert_equal('1024', instance.first.instance_profile.memory)
  67. assert_equal('2', instance.first.instance_profile.cpus)
  68. assert_instance_of(CondorCloud::Image, instance.first.image)
  69. assert_equal('7de6086a9e6ff76dd8bd37c9e770ab4f5cb4649a', instance.first.image.id)
  70. assert_equal('fedora_work_machine-clone-img', instance.first.image.name)
  71. assert_equal('', instance.first.public_addresses.first.ip)
  72. assert_equal('RUNNING', instance.first.state)
  73. end
  74. end
  75. end