testSlapOSPDMSkins.py 66.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
# -*- coding:utf-8 -*-
##############################################################################
#
# Copyright (c) 2002-2013 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
##############################################################################

import transaction
30
from functools import wraps
31 32
from Products.SlapOS.tests.testSlapOSMixin import testSlapOSMixin
from Products.ERP5Type.tests.utils import createZODBPythonScript
33
from DateTime import DateTime
34

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
def simulate(script_id, params_string, code_string):
  def upperWrap(f):
    @wraps(f)
    def decorated(self, *args, **kw):
      if script_id in self.portal.portal_skins.custom.objectIds():
        raise ValueError('Precondition failed: %s exists in custom' % script_id)
      createZODBPythonScript(self.portal.portal_skins.custom,
                          script_id, params_string, code_string)
      try:
        result = f(self, *args, **kw)
      finally:
        if script_id in self.portal.portal_skins.custom.objectIds():
          self.portal.portal_skins.custom.manage_delObjects(script_id)
        transaction.commit()
      return result
    return decorated
  return upperWrap

53 54 55 56
class TestSlapOSPDMSkins(testSlapOSMixin):
  def afterSetUp(self):
    super(TestSlapOSPDMSkins, self).afterSetUp()
    self.new_id = self.generateNewId()
57 58 59 60 61 62 63 64
    self.request_kw = dict(
        software_title=self.generateNewSoftwareTitle(),
        software_type=self.generateNewSoftwareType(),
        instance_xml=self.generateSafeXml(),
        sla_xml=self.generateEmptyXml(),
        shared=False,
        state="started"
    )
65 66 67 68 69 70 71 72
  
  def beforeTearDown(self):
    id_list = []
    for upgrade_decision in self.portal.portal_catalog(
               portal_type="Upgrade Decision", reference="UD-TEST%"):
      id_list.append(upgrade_decision.getId())
    self.portal.upgrade_decision_module.manage_delObjects(id_list)
    self.tic()
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119

  def generateNewId(self):
     return "%sTEST" % self.portal.portal_ids.generateNewId(
         id_group=('slapos_core_test'))
 

  def _makePerson(self,new_id):
    # Clone person document
    person_user = self.portal.person_module.template_member.\
                                 Base_createCloneDocument(batch_mode=1)
    person_user.edit(
      title="live_test_%s" % new_id,
      reference="live_test_%s" % new_id,
      default_email_text="live_test_%s@example.org" % new_id,
    )

    person_user.validate()
    for assignment in person_user.contentValues(portal_type="Assignment"):
      assignment.open()
    transaction.commit()

    return person_user

  def _makeComputer(self,new_id):
    # Clone computer document
    computer = self.portal.computer_module\
      .template_computer.Base_createCloneDocument(batch_mode=1)
    computer.edit(
      title="computer start %s" % (new_id, ),
      reference="TESTCOMPS-%s" % (new_id, )
    )
    computer.validate()

    return computer

  def _makeComputerPartitions(self,computer):
    for i in range(1, 5):
      id_ = 'partition%s' % (i, )
      p = computer.newContent(portal_type='Computer Partition',
        id=id_,
        title=id_,
        reference=id_,
        default_network_address_ip_address='ip_address_%s' % i,
        default_network_address_netmask='netmask_%s' % i)
      p.markFree()
      p.validate()
  
120 121 122 123
  def _markComputerPartitionBusy(self, computer, software_instance):
    for partition in computer.contentValues(portal_type='Computer Partition'):
      if partition.getSlapState() == 'free':
        software_instance.edit(aggregate=partition.getRelativeUrl())
124
        partition.markBusy()
125 126
        break;
  
127 128 129 130 131 132 133 134
  def _makeSoftwareProduct(self, new_id):
    software_product = self.portal.software_product_module\
      .template_software_product.Base_createCloneDocument(batch_mode=1)
    software_product.edit(
      reference='TESTSOFTPROD-%s' % new_id,
      title='Test software product %s' % new_id
    )
    software_product.validate()
135
    software_product.publish()
136 137 138 139 140 141 142 143 144 145 146 147 148 149

    return software_product

  def _makeSoftwareRelease(self, new_id):
    software_release = self.portal.software_release_module\
      .template_software_release.Base_createCloneDocument(batch_mode=1)
    software_release.edit(
      url_string=self.generateNewSoftwareReleaseUrl(),
      reference='TESTSOFTRELS-%s' % new_id,
      title='Start requested for %s' % new_id
    )
    software_release.release()

    return software_release
150 151 152 153 154 155 156 157 158 159 160
  
  def _requestSoftwareRelease(self, new_id, software_product_url, effective_date=None):
    software_release = self._makeSoftwareRelease(new_id)
    if not effective_date:
      effective_date = DateTime()
    software_release.edit(
        aggregate_value=software_product_url,
        effective_date=effective_date
    )
    software_release.publish()
    return software_release
161 162 163 164 165 166 167 168 169
  
  def _makeCustomSoftwareRelease(self, new_id, software_product_url, software_url):
      software_release = self._makeSoftwareRelease(new_id)
      software_release.edit(
          aggregate_value=software_product_url,
          url_string=software_url
      )
      software_release.publish()
      return software_release
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210

  def _makeSoftwareInstallation(self, new_id, computer, software_release_url):
     software_installation = self.portal\
       .software_installation_module.template_software_installation\
       .Base_createCloneDocument(batch_mode=1)
     software_installation.edit(
       url_string=software_release_url,
       aggregate=computer.getRelativeUrl(),
       reference='TESTSOFTINSTS-%s' % new_id,
       title='Start requested for %s' % computer.getUid()
     )
     software_installation.validate()
     software_installation.requestStart()

     return software_installation

  def _makeHostingSubscription(self, new_id):
    hosting_subscription = self.portal\
      .hosting_subscription_module.template_hosting_subscription\
      .Base_createCloneDocument(batch_mode=1)
    hosting_subscription.validate()
    hosting_subscription.edit(
        title= "Test hosting sub start %s" % new_id,
        reference="TESTHSS-%s" % new_id,
    )

    return hosting_subscription

  def _makeSoftwareInstance(self, hosting_subscription, software_url):

    kw = dict(
      software_release=software_url,
      software_type=self.generateNewSoftwareType(),
      instance_xml=self.generateSafeXml(),
      sla_xml=self.generateSafeXml(),
      shared=False,
      software_title=hosting_subscription.getTitle(),
      state='started'
    )
    hosting_subscription.requestStart(**kw)
    hosting_subscription.requestInstance(**kw)
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
    
  def _makeFullHostingSubscription(self, new_id, software_url="", person=None):
    if not person:
      person = self._makePerson(new_id)
    
    hosting_subscription = self.portal\
      .hosting_subscription_module.template_hosting_subscription\
      .Base_createCloneDocument(batch_mode=1)
    hosting_subscription.edit(
        title=self.request_kw['software_title'],
        reference="TESTHS-%s" % new_id,
        url_string=software_url,
        source_reference=self.request_kw['software_type'],
        text_content=self.request_kw['instance_xml'],
        sla_xml=self.request_kw['sla_xml'],
        root_slave=self.request_kw['shared'],
        destination_section=person.getRelativeUrl()
    )
    hosting_subscription.validate()
    self.portal.portal_workflow._jumpToStateFor(hosting_subscription, 'start_requested')

    return hosting_subscription

  def _makeFullSoftwareInstance(self, hosting_subscription, software_url):
    
    software_instance = self.portal.software_instance_module\
        .template_software_instance.Base_createCloneDocument(batch_mode=1)
    software_instance.edit(
        title=self.request_kw['software_title'],
        reference="TESTSI-%s" % self.generateNewId(),
        url_string=software_url,
        source_reference=self.request_kw['software_type'],
        text_content=self.request_kw['instance_xml'],
        sla_xml=self.request_kw['sla_xml'],
        specialise=hosting_subscription.getRelativeUrl()
    )
    hosting_subscription.edit(
        predecessor=software_instance.getRelativeUrl()
    )
    self.portal.portal_workflow._jumpToStateFor(software_instance, 'start_requested')
    software_instance.validate()
    
    return software_instance
254 255 256 257

  def _makeUpgradeDecision(self):
    return self.portal.\
       upgrade_decision_module.newContent(
258
         portal_type="Upgrade Decision",
259
         title="TESTUPDE-%s" % self.new_id)
260
  
261 262 263 264
  def _makeUpgradeDecisionLine(self, upgrade_decision):
    return upgrade_decision.newContent(
         portal_type="Upgrade Decision Line",
         title="TESTUPDE-%s" % self.new_id)
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
  
  
  def test_getSortedSoftwareReleaseListFromSoftwareProduct(self):
    new_id = self.generateNewId()
    software_product = self._makeSoftwareProduct(new_id)
    release_list = software_product.SoftwareProduct_getSortedSoftwareReleaseList(
      software_product.getReference())
    self.assertEqual(release_list, [])
    
    # published software release
    software_release1 = self._makeSoftwareRelease(new_id)
    software_release1.edit(aggregate_value=software_product.getRelativeUrl(),
        url_string='http://example.org/1-%s.cfg' % new_id,
        effective_date=(DateTime() + 5)
    )
    software_release1.publish()
    software_release2 = self._makeSoftwareRelease(self.generateNewId())
    software_release2.edit(aggregate_value=software_product.getRelativeUrl(),
        url_string='http://example.org/2-%s.cfg' % new_id
    )
    software_release2.publish()
    # 1 released software release, should not appear
    software_release3 = self._makeSoftwareRelease(new_id)
    self.assertTrue(software_release3.getValidationState() == 'released')
    software_release3.edit(aggregate_value=software_product.getRelativeUrl(),
        url_string='http://example.org/3-%s.cfg' % new_id
    )
    self.tic()

    release_list = software_product.SoftwareProduct_getSortedSoftwareReleaseList(
      software_product.getReference())
    self.assertEquals([release.getUrlString() for release in release_list],
      ['http://example.org/2-%s.cfg' % new_id, 'http://example.org/1-%s.cfg' % new_id])
    
    
  def test_getSortedSoftwareReleaseListFromSoftwareProduct_Changed(self):
    new_id = self.generateNewId()
    software_product = self._makeSoftwareProduct(new_id)
    release_list = software_product.SoftwareProduct_getSortedSoftwareReleaseList(
      software_product.getReference())
    self.assertEqual(release_list, [])
    
    # 2 published software releases
    software_release2 = self._makeSoftwareRelease(self.generateNewId())
    software_release2.publish()
    software_release2.edit(aggregate_value=software_product.getRelativeUrl(),
        url_string='http://example.org/2-%s.cfg' % new_id,
        effective_date=(DateTime() - 2)
    )
    # Newest software release
    software_release1 = self._makeSoftwareRelease(new_id)
    software_release1.publish()
    software_release1.edit(aggregate_value=software_product.getRelativeUrl(),
        url_string='http://example.org/1-%s.cfg' % new_id,
        effective_date=DateTime()
    )
    self.tic()

    release_list = software_product.SoftwareProduct_getSortedSoftwareReleaseList(
      software_product.getReference())
    self.assertEquals([release.getUrlString() for release in release_list],
      ['http://example.org/1-%s.cfg' % new_id, 'http://example.org/2-%s.cfg' % new_id])
    release_list = software_product.SoftwareProduct_getSortedSoftwareReleaseList(
      software_release_url='http://example.org/1-%s.cfg' % new_id)
    self.assertEquals([release.getUrlString() for release in release_list],
      ['http://example.org/1-%s.cfg' % new_id, 'http://example.org/2-%s.cfg' % new_id])
  
  
  def test_HostingSubscription_getNewerSofwareRelease(self):
    person = self._makePerson(self.new_id)
    computer = self._makeComputer(self.new_id)
    computer.edit(source_administration_value=person)
    software_product = self._makeSoftwareProduct(self.new_id)
    oldest_software_url = 'http://example.org/oldest-%s.cfg' % self.new_id
    newest_software_url = 'http://example.org/newest-%s.cfg' % self.new_id
    
    self._makeCustomSoftwareRelease(self.new_id,
                                software_product.getRelativeUrl(),
                                oldest_software_url)
    self._makeCustomSoftwareRelease(self.generateNewId(),
                                software_product.getRelativeUrl(),
                                newest_software_url)
    self._makeSoftwareInstallation(self.new_id, computer, oldest_software_url)
    
    hosting_subscription = self._makeFullHostingSubscription(self.new_id,
                                    oldest_software_url, person)
    self.tic()
    self.assertEqual(hosting_subscription.HostingSubscription_getNewerSofwareRelease(),
                            None)
    
    self._makeFullSoftwareInstance(hosting_subscription, oldest_software_url)
    self.tic()
    release = hosting_subscription.HostingSubscription_getNewerSofwareRelease()
    self.assertEqual(release.getUrlString(), newest_software_url)

  def testHostingSubscription_getUpgradableSoftwareRelease_no_installation(self):
    person = self._makePerson(self.new_id)
    computer = self._makeComputer(self.new_id)
    computer.edit(source_administration_value=person)
    self._makeComputerPartitions(computer)
    software_product = self._makeSoftwareProduct(self.new_id)
    oldest_software_url = 'http://example.org/oldest-%s.cfg' % self.new_id
    newest_software_url = 'http://example.org/newest-%s.cfg' % self.new_id
    self._makeCustomSoftwareRelease(self.new_id,
                                software_product.getRelativeUrl(),
                                oldest_software_url)
    self._makeSoftwareInstallation(self.new_id, computer, oldest_software_url)
    hs = self._makeFullHostingSubscription(self.new_id,
                                    oldest_software_url, person)
    self.tic()
    self.assertEqual(hs.HostingSubscription_getUpgradableSoftwareRelease(),
                      None)
    
    self._makeFullSoftwareInstance(hs, oldest_software_url)
    self._markComputerPartitionBusy(computer, hs.getPredecessorValue())
    self._makeCustomSoftwareRelease(self.generateNewId(),
                                software_product.getRelativeUrl(),
                                newest_software_url)
    self.tic()
    self.assertEqual(hs.HostingSubscription_getUpgradableSoftwareRelease(),
                      None)
  
  def testHostingSubscription_getUpgradableSoftwareRelease(self):
    person = self._makePerson(self.new_id)
    computer = self._makeComputer(self.new_id)
    computer.edit(source_administration_value=person)
    self._makeComputerPartitions(computer)
    software_product = self._makeSoftwareProduct(self.new_id)
    oldest_software_url = 'http://example.org/oldest-%s.cfg' % self.new_id
    newest_software_url = 'http://example.org/newest-%s.cfg' % self.new_id
    self._makeCustomSoftwareRelease(self.new_id,
                                software_product.getRelativeUrl(),
                                oldest_software_url)
    self._makeSoftwareInstallation(self.new_id, computer, oldest_software_url)
    hs = self._makeFullHostingSubscription(self.new_id,
                                    oldest_software_url, person)
    
    self._makeFullSoftwareInstance(hs, oldest_software_url)
    self._markComputerPartitionBusy(computer, hs.getPredecessorValue())
    self._makeCustomSoftwareRelease(self.generateNewId(),
                                software_product.getRelativeUrl(),
                                newest_software_url)
    self._makeSoftwareInstallation(self.generateNewId(), computer,
                                    newest_software_url)
    # software_release should be ignored!
    software_release = self._makeSoftwareRelease(self.generateNewId())
    self._makeSoftwareInstallation(self.generateNewId(),
                              computer, software_release.getUrlString())
    self.tic()
    release = hs.HostingSubscription_getUpgradableSoftwareRelease()
    self.assertEqual(release.getUrlString(), newest_software_url)
    
    self.portal.portal_workflow._jumpToStateFor(hs, 'destroy_requested')
    self.tic()
    self.assertEqual(hs.HostingSubscription_getUpgradableSoftwareRelease(),
                      None)
                      
422 423 424

  def testUpgradeDecision_getComputer(self):
    computer = self._makeComputer(self.new_id)
425
    upgrade_decision = self._makeUpgradeDecision()
426

427
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
428 429 430 431 432 433 434 435
    upgrade_decision_line.setAggregateValue(computer)

    found_computer = upgrade_decision.UpgradeDecision_getComputer()
    self.assertEquals(computer.getRelativeUrl(),
                      found_computer.getRelativeUrl())

  def testUpgradeDecision_getComputer_2_lines(self):
    computer = self._makeComputer(self.new_id)
436
    upgrade_decision = self._makeUpgradeDecision()
437

438
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
439 440
    upgrade_decision_line.setAggregateValue(computer)

441
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
442 443 444 445 446 447 448

    found_computer = upgrade_decision.UpgradeDecision_getComputer()
    self.assertEquals(computer.getRelativeUrl(),
                      found_computer.getRelativeUrl())

  def testUpgradeDecision_getComputer_2_computer(self):
    computer = self._makeComputer(self.new_id)
449
    upgrade_decision = self._makeUpgradeDecision()
450

451
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
452 453
    upgrade_decision_line.setAggregateValue(computer)

454
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
455 456 457 458 459
    upgrade_decision_line.setAggregateValue(computer)

    self.assertRaises(ValueError, upgrade_decision.UpgradeDecision_getComputer)

  def testUpgradeDecision_getComputer_O_computer(self):
460 461
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
462 463 464 465 466 467 468

    found_computer = upgrade_decision.UpgradeDecision_getComputer()
    self.assertEquals(None, found_computer)


  def testUpgradeDecision_getHostingSubscription(self):
    hosting_subscription = self._makeHostingSubscription(self.new_id)
469
    upgrade_decision = self._makeUpgradeDecision()
470

471
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
472 473 474 475 476 477 478 479 480
    upgrade_decision_line.setAggregateValue(hosting_subscription)

    found_hosting_subscription = upgrade_decision.UpgradeDecision_getHostingSubscription()
    self.assertEquals(hosting_subscription.getRelativeUrl(),
                      found_hosting_subscription.getRelativeUrl())


  def testUpgradeDecision_getHostingSubscription_2_lines(self):
    hosting_subscription = self._makeHostingSubscription(self.new_id)
481
    upgrade_decision = self._makeUpgradeDecision()
482

483
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
484 485
    upgrade_decision_line.setAggregateValue(hosting_subscription)

486
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
487 488 489 490 491 492 493 494

    found_hosting_subscription = upgrade_decision.UpgradeDecision_getHostingSubscription()
    self.assertEquals(hosting_subscription.getRelativeUrl(),
                      found_hosting_subscription.getRelativeUrl())


  def testUpgradeDecision_getHostingSubscription_2_hosting(self):
    hosting_subscription = self._makeHostingSubscription(self.new_id)
495
    upgrade_decision = self._makeUpgradeDecision()
496

497
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
498 499
    upgrade_decision_line.setAggregateValue(hosting_subscription)

500
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
501 502 503 504 505
    upgrade_decision_line.setAggregateValue(hosting_subscription)

    self.assertRaises(ValueError, upgrade_decision.UpgradeDecision_getHostingSubscription)

  def testUpgradeDecision_getHostingSubscription_O_hosting(self):
506 507
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
508 509 510 511 512 513 514

    found_hosting_subscription = upgrade_decision.UpgradeDecision_getHostingSubscription()
    self.assertEquals(None, found_hosting_subscription)

     
  def testUpgradeDecision_getSoftwareRelease(self):
    software_release = self._makeSoftwareRelease(self.new_id)
515
    upgrade_decision = self._makeUpgradeDecision()
516

517
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
518 519 520 521 522 523 524 525
    upgrade_decision_line.setAggregateValue(software_release)

    found_software_release = upgrade_decision.UpgradeDecision_getSoftwareRelease()
    self.assertEquals(software_release.getRelativeUrl(),
                      found_software_release.getRelativeUrl())

  def testUpgradeDecision_getSoftwareRelease_2_lines(self):
    software_release = self._makeSoftwareRelease(self.new_id)
526
    upgrade_decision = self._makeUpgradeDecision()
527

528
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
529 530
    upgrade_decision_line.setAggregateValue(software_release)

531
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
532 533 534 535 536 537 538

    found_software_release = upgrade_decision.UpgradeDecision_getSoftwareRelease()
    self.assertEquals(software_release.getRelativeUrl(),
                      found_software_release.getRelativeUrl())

  def testUpgradeDecision_getSoftwareRelease_2_sr(self):
    software_release = self._makeSoftwareRelease(self.new_id)
539
    upgrade_decision = self._makeUpgradeDecision()
540

541
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
542 543
    upgrade_decision_line.setAggregateValue(software_release)

544
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
545 546 547 548 549
    upgrade_decision_line.setAggregateValue(software_release)

    self.assertRaises(ValueError, upgrade_decision.UpgradeDecision_getSoftwareRelease)

  def testUpgradeDecision_getSoftwareRelease_O_sr(self):
550 551
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
552 553 554 555 556 557 558 559 560 561 562

    found_software_release = upgrade_decision.UpgradeDecision_getSoftwareRelease()
    self.assertEquals(None, found_software_release)

  def testUpgradeDecision_upgradeHostingSubscription(self):

    person = self._makePerson(self.new_id)
    hosting_subscription = self._makeHostingSubscription(self.new_id)
    hosting_subscription.edit(
          destination_section_value = person.getRelativeUrl())

563
    self._makeSoftwareInstance(hosting_subscription,
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
                               hosting_subscription.getUrlString())
   
    software_release = self._makeSoftwareRelease(self.new_id)
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
    upgrade_decision_line.setAggregateValueList(
       [software_release, hosting_subscription])
    self.tic()
   
    slap_state = hosting_subscription.getSlapState()
    
    self.assertFalse(upgrade_decision.UpgradeDecision_upgradeHostingSubscription())
    self.assertNotEqual(software_release.getUrlString(),
                     hosting_subscription.getUrlString())

    upgrade_decision.confirm()
    upgrade_decision.start()

    # Check that url_string change, but slap state doesn't
    self.assertNotEqual(software_release.getUrlString(),
                     hosting_subscription.getUrlString())

    self.assertTrue(upgrade_decision.UpgradeDecision_upgradeHostingSubscription())
    self.assertEqual(software_release.getUrlString(),
                     hosting_subscription.getUrlString())

    self.assertEqual(slap_state, hosting_subscription.getSlapState())
    self.assertEqual('stopped', upgrade_decision.getSimulationState())

593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
  def testUpgradeDecision_processUpgradeeHostingSubscription(self):
    person = self._makePerson(self.new_id)
    hosting_subscription = self._makeHostingSubscription(self.new_id)
    hosting_subscription.edit(
          destination_section_value = person.getRelativeUrl())

    self._makeSoftwareInstance(hosting_subscription,
                               hosting_subscription.getUrlString())
   
    software_release = self._makeSoftwareRelease(self.new_id)
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
    upgrade_decision_line.setAggregateValueList(
       [software_release, hosting_subscription])
    self.tic()
   
    slap_state = hosting_subscription.getSlapState()
    
    self.assertFalse(upgrade_decision.UpgradeDecision_processUpgrade())
    self.assertNotEqual(software_release.getUrlString(),
                     hosting_subscription.getUrlString())

    upgrade_decision.confirm()
    upgrade_decision.start()

    # Check that url_string change, but slap state doesn't
    self.assertNotEqual(software_release.getUrlString(),
                     hosting_subscription.getUrlString())

    self.assertTrue(upgrade_decision.UpgradeDecision_processUpgrade())
    self.assertEqual(software_release.getUrlString(),
                     hosting_subscription.getUrlString())

    self.assertEqual(slap_state, hosting_subscription.getSlapState())
    self.assertEqual('stopped', upgrade_decision.getSimulationState())


630 631 632 633 634 635 636
  def testUpgradeDecision_upgradeHostingSubscription_no_software_release(self):

    person = self._makePerson(self.new_id)
    hosting_subscription = self._makeHostingSubscription(self.new_id)
    hosting_subscription.edit(
          destination_section_value = person.getRelativeUrl())

637
    self._makeSoftwareInstance(hosting_subscription,
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
                               hosting_subscription.getUrlString())
   
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
    upgrade_decision_line.setAggregateValueList([hosting_subscription])
    self.tic()
   
    upgrade_decision.confirm()
    upgrade_decision.start()

    self.assertFalse(upgrade_decision.UpgradeDecision_upgradeHostingSubscription())
    self.assertEqual('started', upgrade_decision.getSimulationState())

  def testUpgradeDecision_upgradeHostingSubscription_no_hosting_subscripion(self):

653
    software_release = self._makeSoftwareRelease(self.new_id)
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
    upgrade_decision_line.setAggregateValueList([software_release])
    self.tic()
    
    upgrade_decision.confirm()
    upgrade_decision.start()

    self.assertFalse(upgrade_decision.UpgradeDecision_upgradeHostingSubscription())
    self.assertEqual('started', upgrade_decision.getSimulationState())
    
  def testUpgradeDecision_upgradeComputer_no_software_release(self):

    person = self._makePerson(self.new_id)
    computer = self._makeComputer(self.new_id)
    computer.edit(
          source_administration_value = person.getRelativeUrl())

    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
    upgrade_decision_line.setAggregateValueList([computer])
    self.tic()
   
    upgrade_decision.confirm()
    upgrade_decision.start()

    self.assertFalse(upgrade_decision.UpgradeDecision_upgradeComputer())
    self.assertEqual('started', upgrade_decision.getSimulationState())


  def testUpgradeDecision_upgradeComputer_no_hosting_subscripion(self):

686
    software_release = self._makeSoftwareRelease(self.new_id)
687 688 689 690 691 692 693 694 695 696 697 698 699 700
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
    upgrade_decision_line.setAggregateValueList([software_release])
    self.tic()
    
    upgrade_decision.confirm()
    upgrade_decision.start()

    self.assertFalse(upgrade_decision.UpgradeDecision_upgradeComputer())
    self.assertEqual('started', upgrade_decision.getSimulationState())
    
  def testUpgradeDecision_upgradeComputer(self):
    person = self._makePerson(self.new_id)
    computer = self._makeComputer(self.new_id)
701
    software_release = self._makeSoftwareRelease(self.new_id)
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
    upgrade_decision_line.setAggregateValueList([software_release, computer])
    url = software_release.getUrlString()
    
    self.tic()

    self.assertFalse(upgrade_decision.UpgradeDecision_upgradeComputer())

    upgrade_decision.confirm()
    upgrade_decision.start()

    self.assertTrue(upgrade_decision.UpgradeDecision_upgradeComputer())
    self.tic()
    
    software_installation = computer.getAggregateRelatedValue(
            portal_type='Software Installation')
    self.assertEqual('start_requested', software_installation.getSlapState())
    self.assertEqual(url, software_installation.getUrlString())
    self.assertEqual('validated', software_installation.getValidationState())
    self.assertEqual('stopped', upgrade_decision.getSimulationState())

724

725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
  def testUpgradeDecision_processUpgradeComputer(self):
    person = self._makePerson(self.new_id)
    computer = self._makeComputer(self.new_id)
    software_release = self._makeSoftwareRelease(self.new_id)
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
    upgrade_decision_line.setAggregateValueList([software_release, computer])
    url = software_release.getUrlString()
    
    self.tic()

    self.assertFalse(upgrade_decision.UpgradeDecision_processUpgrade())

    upgrade_decision.confirm()
    upgrade_decision.start()

    self.assertTrue(upgrade_decision.UpgradeDecision_processUpgrade())
    self.tic()
    
    software_installation = computer.getAggregateRelatedValue(
            portal_type='Software Installation')
    self.assertEqual('start_requested', software_installation.getSlapState())
    self.assertEqual(url, software_installation.getUrlString())
    self.assertEqual('validated', software_installation.getValidationState())
    self.assertEqual('stopped', upgrade_decision.getSimulationState())


752
  def testSoftwareRelease_createUpgradeDecision_computer(self):
753 754 755 756 757 758
    person = self._makePerson(self.new_id)
    computer = self._makeComputer(self.new_id)
    computer.edit(source_administration_value=person)
    software_release = self._makeSoftwareRelease(self.new_id)
    
    upgrade_decision = software_release.SoftwareRelease_createUpgradeDecision(
759
          source_url=computer.getRelativeUrl(),
760 761 762
          title="TEST-SRUPDE-%s" % self.new_id)
    self.tic()
    
763
    self.assertEqual(upgrade_decision.getSimulationState(), 'draft')
764 765 766 767 768 769 770
    self.assertEqual(upgrade_decision.getDestinationSection(),
                       person.getRelativeUrl())
    
    decision_line = upgrade_decision.contentValues(
                    portal_type='Upgrade Decision Line')[0]
    
    self.assertEqual(decision_line.getTitle(),
771
                        'Request decision upgrade for %s on Computer %s' % (
772 773 774 775 776 777 778 779
                        software_release.getTitle(), computer.getReference())
                    )
    self.assertEqual(decision_line.getAggregate(portal_type='Computer'),
                      computer.getRelativeUrl())
    self.assertEqual(decision_line.getAggregate(portal_type='Software Release'),
                      software_release.getRelativeUrl())
  
  
780 781 782 783 784 785 786 787 788 789 790 791
  def testSoftwareRelease_createUpgradeDecision_hostingSubscription(self):
    person = self._makePerson(self.new_id)
    hosting_subscription = self._makeHostingSubscription(self.new_id)
    hosting_subscription.edit(
          destination_section_value = person.getRelativeUrl())
    software_release = self._makeSoftwareRelease(self.new_id)
    
    upgrade_decision = software_release.SoftwareRelease_createUpgradeDecision(
          source_url=hosting_subscription.getRelativeUrl(),
          title="TEST-SRUPDE-%s" % self.new_id)
    self.tic()
    
792
    self.assertEqual(upgrade_decision.getSimulationState(), 'draft')
793 794 795 796 797 798 799 800 801 802 803 804
    self.assertEqual(upgrade_decision.getDestinationSection(),
                       person.getRelativeUrl())
    
    decision_line = upgrade_decision.contentValues(
                    portal_type='Upgrade Decision Line')[0]
                    
    self.assertEqual(decision_line.getAggregate(portal_type='Hosting Subscription'),
                      hosting_subscription.getRelativeUrl())
    self.assertEqual(decision_line.getAggregate(portal_type='Software Release'),
                      software_release.getRelativeUrl())
  
  
805
  def testSoftwareRelease_getUpgradeDecisionInProgress(self):
806
    computer = self._makeComputer(self.new_id)
807 808 809
    software_product = self._makeSoftwareProduct(self.new_id)
    software_release = self._requestSoftwareRelease(self.new_id,
                                    software_product.getRelativeUrl())
810 811 812 813 814
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
    upgrade_decision_line.setAggregateValueList([software_release, computer])
    software_release2 = self._makeSoftwareRelease(self.generateNewId())
    upgrade_decision.confirm()
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840
    reference = upgrade_decision.getReference()
    
    self.tic()
    
    in_progress = software_release.SoftwareRelease_getUpgradeDecisionInProgress(
                                computer.getUid())
    self.assertEqual(in_progress.getReference(), reference)
    
    in_progress = software_release.SoftwareRelease_getUpgradeDecisionInProgress(
                                software_release.getUid())
    self.assertEqual(in_progress.getReference(), reference)
    
    in_progress = software_release2.SoftwareRelease_getUpgradeDecisionInProgress(
                                computer.getUid())
    self.assertEqual(in_progress, None)
  
  def testSoftwareRelease_getUpgradeDecisionInProgress_cancelled(self):
    computer = self._makeComputer(self.new_id)
    software_product = self._makeSoftwareProduct(self.new_id)
    software_release = self._requestSoftwareRelease(self.new_id,
                                    software_product.getRelativeUrl())
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
    upgrade_decision_line.setAggregateValueList([software_release, computer])
    upgrade_decision.confirm()
    upgrade_decision.cancel()
841 842
    
    self.tic()
843 844 845
    in_progress = software_release.SoftwareRelease_getUpgradeDecisionInProgress(
                                computer.getUid())
    self.assertEqual(in_progress, None)
846
    
847 848 849 850 851 852
    upgrade_decision2 = self._makeUpgradeDecision()
    upgrade_decision_line2 = self._makeUpgradeDecisionLine(upgrade_decision2)
    upgrade_decision_line2.setAggregateValueList([software_release, computer])
    upgrade_decision2.confirm()
    upgrade_decision2.start()
    self.tic()
853
    
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
    in_progress = software_release.SoftwareRelease_getUpgradeDecisionInProgress(
                                computer.getUid())
    self.assertEqual(in_progress.getReference(), upgrade_decision2.getReference())
  
  def testSoftwareRelease_getUpgradeDecisionInProgress_hosting_subs(self):
    person = self._makePerson(self.new_id)
    hosting_subscription = self._makeHostingSubscription(self.new_id)
    hosting_subscription.edit(
          destination_section_value = person.getRelativeUrl())
    software_product = self._makeSoftwareProduct(self.new_id)
    software_release = self._requestSoftwareRelease(self.new_id,
                                    software_product.getRelativeUrl())
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
    upgrade_decision_line.setAggregateValueList([software_release,
                                                      hosting_subscription])
    upgrade_decision.confirm()
    reference = upgrade_decision.getReference()
    self.tic()
873
    
874 875 876
    in_progress = software_release.SoftwareRelease_getUpgradeDecisionInProgress(
                                hosting_subscription.getUid())
    self.assertEqual(in_progress.getReference(), reference)
877
    
878 879
    upgrade_decision.cancel()
    self.tic()
880
    
881 882 883
    in_progress = software_release.SoftwareRelease_getUpgradeDecisionInProgress(
                                hosting_subscription.getUid())
    self.assertEqual(in_progress, None)
884
  
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977
  
  def testSoftwareRelease_getUpgradeDecisionInProgress_software_product(self):
    computer = self._makeComputer(self.new_id)
    software_product = self._makeSoftwareProduct(self.new_id)
    software_release = self._requestSoftwareRelease(self.new_id,
                                    software_product.getRelativeUrl())
    software_release2 = self._requestSoftwareRelease(self.generateNewId(),
                                      software_product.getRelativeUrl())
    software_release3 = self._makeSoftwareRelease(self.generateNewId())
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
    upgrade_decision_line.setAggregateValueList([software_release, computer])
    upgrade_decision.confirm()
    reference = upgrade_decision.getReference()
    
    self.tic()
    
    in_progress = software_release.SoftwareRelease_getUpgradeDecisionInProgress(
                                computer.getUid())
    self.assertEqual(in_progress.getReference(), reference)
    
    in_progress = software_release2.SoftwareRelease_getUpgradeDecisionInProgress(
                                computer.getUid())
    self.assertEqual(in_progress.getReference(), reference)
    
    in_progress = software_release3.SoftwareRelease_getUpgradeDecisionInProgress(
                                computer.getUid())
    self.assertEqual(in_progress, None)
  
  
  def testSoftwareRelease_getUpgradeDecisionInProgress_software_product_hs(self):
    person = self._makePerson(self.new_id)
    hosting_subscription = self._makeHostingSubscription(self.new_id)
    hosting_subscription.edit(
          destination_section_value = person.getRelativeUrl())
    software_product = self._makeSoftwareProduct(self.new_id)
    software_release = self._requestSoftwareRelease(self.new_id,
                                    software_product.getRelativeUrl())
    software_release2 = self._requestSoftwareRelease(self.generateNewId(),
                                      software_product.getRelativeUrl())
    software_release3 = self._makeSoftwareRelease(self.generateNewId())
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
    upgrade_decision_line.setAggregateValueList([software_release,
                                                      hosting_subscription])
    upgrade_decision.confirm()
    reference = upgrade_decision.getReference()
    reference = upgrade_decision.getReference()
    
    self.tic()
    
    in_progress = software_release.SoftwareRelease_getUpgradeDecisionInProgress(
                                hosting_subscription.getUid())
    self.assertEqual(in_progress.getReference(), reference)
    
    in_progress = software_release2.SoftwareRelease_getUpgradeDecisionInProgress(
                                hosting_subscription.getUid())
    self.assertEqual(in_progress.getReference(), reference)
    
    in_progress = software_release3.SoftwareRelease_getUpgradeDecisionInProgress(
                                hosting_subscription.getUid())
    self.assertEqual(in_progress, None)
  
  
  def testUpgradeDecision_tryToCancel(self):
    computer = self._makeComputer(self.new_id)
    software_release = self._makeSoftwareRelease(self.new_id)
    software_release2 = self._makeSoftwareRelease(self.generateNewId())
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
    upgrade_decision_line.setAggregateValueList([software_release, computer])
    upgrade_decision.confirm()
    
    upgrade_decision2 = self._makeUpgradeDecision()
    upgrade_decision_line2 = self._makeUpgradeDecisionLine(upgrade_decision2)
    upgrade_decision_line2.setAggregateValueList([software_release, computer])
    upgrade_decision2.confirm()
    upgrade_decision2.start()
    
    url = software_release.getUrlString()
    url2 = software_release2.getUrlString()
    
    # Cancel is not possible with the same url_string
    self.assertEqual(upgrade_decision.UpgradeDecision_tryToCancel(url), False)
    self.assertEqual(upgrade_decision.UpgradeDecision_tryToCancel(url2), True)
    self.assertEqual(upgrade_decision.getSimulationState(), 'cancelled')
    
    # Cancel is no longer possible
    self.assertEqual(upgrade_decision2.UpgradeDecision_tryToCancel(url), False)
    self.assertEqual(upgrade_decision2.UpgradeDecision_tryToCancel(url2), False)
    self.assertEqual(upgrade_decision2.getSimulationState(), 'started')
    
    
978 979 980
  def testComputer_checkAndCreateUpgradeDecision(self):
    person = self._makePerson(self.new_id)
    computer = self._makeComputer(self.new_id)
981 982
    computer.edit(source_administration_value=person,
                  allocation_scope="open/public")
983 984 985 986 987 988 989
    software_product = self._makeSoftwareProduct(self.new_id)
    software_release = self._requestSoftwareRelease(self.new_id,
                                    software_product.getRelativeUrl())
    self._makeSoftwareInstallation(self.new_id,
                              computer, software_release.getUrlString())
    self.tic()
    upgrade_decision = computer.Computer_checkAndCreateUpgradeDecision()
990
    self.assertEqual(len(upgrade_decision), 0)
991 992 993 994 995 996 997 998 999 1000
    
    software_release2 = self._requestSoftwareRelease(self.generateNewId(),
                                      software_product.getRelativeUrl())
    # Should be ignored, Publication Date is for tomorrow
    self._requestSoftwareRelease(self.generateNewId(),
                                      software_product.getRelativeUrl(),
                                      (DateTime() + 1))
    self.tic()
    
    upgrade_decision = computer.Computer_checkAndCreateUpgradeDecision()
1001
    self.assertEqual(len(upgrade_decision), 1)
1002
    self.assertEqual(upgrade_decision[0].getSimulationState(), 'started')
1003
    
1004
    computer_aggregate = upgrade_decision[0].UpgradeDecision_getComputer()
1005 1006
    self.assertEqual(computer_aggregate.getReference(),
                      computer.getReference())
1007 1008
    release = upgrade_decision[0].UpgradeDecision_getSoftwareRelease()
    self.assertEqual(release.getUrlString(),
1009 1010 1011
                                software_release2.getUrlString())
    self.tic()
    upgrade_decision2 = computer.Computer_checkAndCreateUpgradeDecision()
1012 1013
    self.assertEqual(len(upgrade_decision2), 0)
  
1014
  def testComputer_checkAndCreateUpgradeDecision_personal_with_exist(self):
1015 1016
    person = self._makePerson(self.new_id)
    computer = self._makeComputer(self.new_id)
1017 1018
    computer.edit(source_administration_value=person,
                  allocation_scope="open/personal")
1019 1020 1021 1022 1023 1024 1025 1026
    software_product = self._makeSoftwareProduct(self.new_id)
    software_release = self._requestSoftwareRelease(self.new_id,
                                    software_product.getRelativeUrl())
    self._makeSoftwareInstallation(self.new_id,
                              computer, software_release.getUrlString())
    self._requestSoftwareRelease(self.generateNewId(),
                                      software_product.getRelativeUrl())
    self.tic()
1027
    
1028
    upgrade_decision = computer.Computer_checkAndCreateUpgradeDecision()[0]
1029
    self.assertEqual(upgrade_decision.getSimulationState(), 'planned')
1030 1031 1032 1033 1034 1035 1036 1037
    
    software_release3 = self._requestSoftwareRelease(self.generateNewId(),
                                      software_product.getRelativeUrl())
    self.tic()
    
    upgrade_decision2 = computer.Computer_checkAndCreateUpgradeDecision()[0]
    
    self.assertEqual(upgrade_decision.getSimulationState(), 'cancelled')
1038
    self.assertEqual(upgrade_decision2.getSimulationState(), 'planned')
1039 1040 1041
    release = upgrade_decision2.UpgradeDecision_getSoftwareRelease()
    self.assertEqual(release.getUrlString(),
                                software_release3.getUrlString())
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
  
  def testComputer_checkAndCreateUpgradeDecision_public_with_exist(self):
    person = self._makePerson(self.new_id)
    computer = self._makeComputer(self.new_id)
    computer.edit(source_administration_value=person,
                  allocation_scope="open/public")
    software_product = self._makeSoftwareProduct(self.new_id)
    software_release = self._requestSoftwareRelease(self.new_id,
                                    software_product.getRelativeUrl())
    self._makeSoftwareInstallation(self.new_id,
                              computer, software_release.getUrlString())
    self._requestSoftwareRelease(self.generateNewId(),
                                      software_product.getRelativeUrl())
    self.tic()
    
    upgrade_decision = computer.Computer_checkAndCreateUpgradeDecision()[0]
    self.assertEqual(upgrade_decision.getSimulationState(), 'started')
    
    self._requestSoftwareRelease(self.generateNewId(),
                                      software_product.getRelativeUrl())
    self.tic()
    
    upgrade_decision2 = computer.Computer_checkAndCreateUpgradeDecision()
    
    self.assertEqual(len(upgrade_decision2), 0)
    self.assertEqual(upgrade_decision.getSimulationState(), 'started')
1068 1069
    
  
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082
  def testComputer_hostingSubscriptionCreateUpgradeDecision_no_newer(self):
    person = self._makePerson(self.new_id)
    computer = self._makeComputer(self.new_id)
    computer.edit(source_administration_value=person)
    self._makeComputerPartitions(computer)
    software_product = self._makeSoftwareProduct(self.new_id)
    software_release = self._requestSoftwareRelease(self.new_id,
                                    software_product.getRelativeUrl())
    url_string = software_release.getUrlString()
    self._makeSoftwareInstallation(self.new_id, computer, url_string)
    self.tic()
    
    upgrade_decision = computer.Computer_hostingSubscriptionCreateUpgradeDecision()
1083
    self.assertEqual(len(upgrade_decision), 0)
1084 1085 1086 1087 1088 1089 1090
    
    # Create Hosting Subscription
    hosting_subscription = self._makeFullHostingSubscription(self.new_id,
                                    url_string, person)
    self.tic()
    
    upgrade_decision = computer.Computer_hostingSubscriptionCreateUpgradeDecision()
1091
    self.assertEqual(len(upgrade_decision), 0)
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101
    
    self._makeFullSoftwareInstance(hosting_subscription, url_string)
    self._markComputerPartitionBusy(computer,
                                    hosting_subscription.getPredecessorValue())
    
    self._requestSoftwareRelease(self.generateNewId(),
                                    software_product.getRelativeUrl())
    self.tic()
    
    upgrade_decision = computer.Computer_hostingSubscriptionCreateUpgradeDecision()
1102
    self.assertEqual(len(upgrade_decision), 0)
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
  
  def testComputer_hostingSubscriptionCreateUpgradeDecision(self):
    person = self._makePerson(self.new_id)
    computer = self._makeComputer(self.new_id)
    computer.edit(source_administration_value=person)
    self._makeComputerPartitions(computer)
    software_product = self._makeSoftwareProduct(self.new_id)
    software_release = self._requestSoftwareRelease(self.new_id,
                                    software_product.getRelativeUrl())
    url_string = software_release.getUrlString()
    
    self._makeSoftwareInstallation(self.new_id, computer, url_string)
    
    # Create Hosting Subscription and Software Instance
    hosting_subscription = self._makeFullHostingSubscription(self.new_id,
                                    url_string, person)
    self._makeFullSoftwareInstance(hosting_subscription, url_string)
    self._markComputerPartitionBusy(computer,
                                    hosting_subscription.getPredecessorValue())
    
    # Install the Newest software release
    software_release2 = self._requestSoftwareRelease(self.generateNewId(),
                                      software_product.getRelativeUrl())
1126
    self._makeSoftwareInstallation(self.generateNewId(), computer,
1127 1128 1129
                                    software_release2.getUrlString())
    self.tic()
    
1130
    up_decision = computer.Computer_hostingSubscriptionCreateUpgradeDecision()[0]
1131
    self.assertEqual(up_decision.getSimulationState(), 'planned')
1132
    
1133
    self.assertEqual(up_decision.UpgradeDecision_getHostingSubscription().\
1134 1135
                      getReference(), hosting_subscription.getReference())

1136
    self.assertEqual(up_decision.UpgradeDecision_getSoftwareRelease().\
1137 1138 1139
                              getUrlString(), software_release2.getUrlString())
    
    self.tic()
1140 1141
    up_decision2 = computer.Computer_hostingSubscriptionCreateUpgradeDecision()
    self.assertEqual(len(up_decision2), 0)
1142
  
1143 1144
  
  def testComputer_hostingSubscriptionCreateUpgradeDecision_with_exist(self):
1145 1146
    person = self._makePerson(self.new_id)
    computer = self._makeComputer(self.new_id)
1147 1148
    computer.edit(source_administration_value=person)
    self._makeComputerPartitions(computer)
1149
    software_product = self._makeSoftwareProduct(self.new_id)
1150 1151 1152
    software_release = self._requestSoftwareRelease(self.new_id,
                                    software_product.getRelativeUrl())
    url_string = software_release.getUrlString()
1153
    
1154
    self._makeSoftwareInstallation(self.new_id, computer, url_string)
1155
    
1156 1157 1158 1159 1160 1161
    # Create Hosting Subscription and Software Instance
    hosting_subscription = self._makeFullHostingSubscription(self.new_id,
                                    url_string, person)
    self._makeFullSoftwareInstance(hosting_subscription, url_string)
    self._markComputerPartitionBusy(computer,
                                    hosting_subscription.getPredecessorValue())
1162
    
1163 1164 1165 1166 1167
    # Install the Newest software release
    software_release2 = self._requestSoftwareRelease(self.generateNewId(),
                                      software_product.getRelativeUrl())
    self._makeSoftwareInstallation(self.generateNewId(), computer,
                                    software_release2.getUrlString())
1168 1169
    self.tic()
    
1170
    up_decision = computer.Computer_hostingSubscriptionCreateUpgradeDecision()[0]
1171
    self.assertEqual(up_decision.getSimulationState(), 'planned')
1172
    
1173 1174 1175 1176 1177
    # Install the another software release
    software_release3 = self._requestSoftwareRelease(self.generateNewId(),
                                      software_product.getRelativeUrl())
    self._makeSoftwareInstallation(self.generateNewId(), computer,
                                    software_release3.getUrlString())
1178 1179
    self.tic()
    
1180
    up_decision2 = computer.Computer_hostingSubscriptionCreateUpgradeDecision()[0]
1181
    self.assertEqual(up_decision2.getSimulationState(), 'planned')
1182 1183 1184 1185
    self.assertEqual(up_decision.getSimulationState(), 'cancelled')
    release = up_decision2.UpgradeDecision_getSoftwareRelease()
    self.assertEqual(release.getUrlString(),
                                software_release3.getUrlString())
1186
    
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525
  
  def testBase_acceptUpgradeDecision_no_reference(self):
    upgrade_decision = self._makeUpgradeDecision()
    self.assertRaises(ValueError, self.portal.Base_acceptUpgradeDecision, None)
    
  def testBase_acceptUpgradeDecision_duplicated_reference(self):
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTBADREFERENCE")
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTBADREFERENCE")
    self.tic()
    self.assertRaises(ValueError, self.portal.Base_acceptUpgradeDecision, None)

  def testBase_acceptUpgradeDecision_no_upgrade_decision(self):
    redirect_url = self.portal.Base_acceptUpgradeDecision('UD-UNEXISTING')
    self.assertTrue(redirect_url.endswith(
      "?portal_status_message=Unable%20to%20find%20the%20Upgrade%20Decision."), 
      "%s contains the wrong message" %  redirect_url)
     
  def testBase_acceptUpgradeDecision_draft_upgrade_decision(self):
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTDRAFT")
    self.tic()
    redirect_url = self.portal.Base_acceptUpgradeDecision('UD-TESTDRAFT')
    self.assertTrue(redirect_url.endswith(
      "?portal_status_message=Sorry%2C%20the%20upgrade%20is%20not%20possible%20yet%21"), 
      "%s contains the wrong message" %  redirect_url)

  def testBase_acceptUpgradeDecision_planned_upgrade_decision(self):
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTPLANNED")
    upgrade_decision.plan()
    self.tic()
    redirect_url = self.portal.Base_acceptUpgradeDecision('UD-TESTPLANNED')
    self.assertTrue(redirect_url.endswith(
      "?portal_status_message=Sorry%2C%20the%20upgrade%20is%20not%20possible%20yet%21"), 
      "%s contains the wrong message" %  redirect_url)

  def testBase_acceptUpgradeDecision_confirmed_upgrade_decision(self):
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTCONFIRMED")
    upgrade_decision.confirm()
    self.tic()
    redirect_url = self.portal.Base_acceptUpgradeDecision('UD-TESTCONFIRMED')
    self.assertTrue(redirect_url.endswith(
      "?portal_status_message=This%20Upgrade%20Decision%20has%20been%20"\
      "requested%2C%20it%20will%20be%20processed%20in%20few%20minutes."), 
      "%s contains the wrong message" %  redirect_url)
    self.assertEquals(upgrade_decision.getSimulationState(), 'started')

  def testBase_acceptUpgradeDecision_started_decision(self):
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTSTARTED")
    upgrade_decision.start()
    self.tic()
    redirect_url = self.portal.Base_acceptUpgradeDecision('UD-TESTSTARTED')
    self.assertTrue(redirect_url.endswith(
     "?portal_status_message=This%20Upgrade%20Decision%20is%20already%20Started."), 
     "%s contains the wrong message" %  redirect_url)

  def testBase_acceptUpgradeDecision_stop_decision(self):
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTSTOP")
    upgrade_decision.start()
    upgrade_decision.stop()
    self.tic()
    redirect_url = self.portal.Base_acceptUpgradeDecision('UD-TESTSTOP')
    self.assertTrue(redirect_url.endswith(
      "?portal_status_message=This%20Upgrade%20Decision%20has%20been%20already%20processed."),
      "%s contains the wrong message" %  redirect_url)

  def testBase_acceptUpgradeDecision_delivered_decision(self):
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTDELIVERED")
    upgrade_decision.start()
    upgrade_decision.stop()
    upgrade_decision.deliver()
    self.tic()
    redirect_url = self.portal.Base_acceptUpgradeDecision('UD-TESTDELIVERED')
    self.assertTrue(redirect_url.endswith(
      "?portal_status_message=This%20Upgrade%20Decision%20has%20been%20already%20processed."),
      "%s contains the wrong message" %  redirect_url)

  def testBase_acceptUpgradeDecision_cancelled_decision(self):
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTCANCELLED")
    upgrade_decision.cancel()
    self.tic()
    redirect_url = self.portal.Base_acceptUpgradeDecision('UD-TESTCANCELLED')
    self.assertTrue(redirect_url.endswith(
      "?portal_status_message=Sorry%2C%20the%20upgrade%20is%20not%20possble%2C%20Upgrade%20Decision%20was%20Canceled%20or%20Rejected%21"),
      "%s contains the wrong message" %  redirect_url)

  def testBase_acceptUpgradeDecision_rejected_decision(self):
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTREJECT")
    upgrade_decision.cancel()
    self.tic()
    redirect_url = self.portal.Base_acceptUpgradeDecision('UD-TESTREJECT')
    self.assertTrue(redirect_url.endswith(
      "?portal_status_message=Sorry%2C%20the%20upgrade%20is%20not%20possble%2C%20Upgrade%20Decision%20was%20Canceled%20or%20Rejected%21"),
      "%s contains the wrong message" %  redirect_url)

  def testBase_rejectUpgradeDecision_no_reference(self):
    upgrade_decision = self._makeUpgradeDecision()
    self.assertRaises(ValueError, self.portal.Base_rejectUpgradeDecision, None)
    
  def testBase_rejectUpgradeDecision_duplicated_reference(self):
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTBADREFERENCE")
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTBADREFERENCE")
    self.tic()
    self.assertRaises(ValueError, self.portal.Base_acceptUpgradeDecision, None)

  def testBase_rejectUpgradeDecision_no_upgrade_decision(self):
    redirect_url = self.portal.Base_rejectUpgradeDecision('UD-UNEXISTING')
    self.assertTrue(redirect_url.endswith(
      "?portal_status_message=Unable%20to%20find%20the%20Upgrade%20Decision."), 
      "%s contains the wrong message" %  redirect_url)
     
  def testBase_rejectUpgradeDecision_draft_upgrade_decision(self):
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTDRAFT")
    self.tic()
    redirect_url = self.portal.Base_rejectUpgradeDecision('UD-TESTDRAFT')
    self.assertTrue(redirect_url.endswith(
      "?portal_status_message=Thanks%20Upgrade%20Decision%20has%20been"\
      "%20rejected%20Successfully%20%28You%20cannot%20use%20it%20anymore%29."), 
      "%s contains the wrong message" %  redirect_url)
    self.assertEquals(upgrade_decision.getSimulationState(), 'rejected')

  def testBase_rejectUpgradeDecision_planned_upgrade_decision(self):
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTPLANNED")
    upgrade_decision.plan()
    self.tic()
    redirect_url = self.portal.Base_rejectUpgradeDecision('UD-TESTPLANNED')
    self.assertTrue(redirect_url.endswith(
      "?portal_status_message=Thanks%20Upgrade%20Decision%20has%20been"\
      "%20rejected%20Successfully%20%28You%20cannot%20use%20it%20anymore%29."), 
      "%s contains the wrong message" %  redirect_url)
    self.assertEquals(upgrade_decision.getSimulationState(), 'rejected')

  def testBase_rejectUpgradeDecision_confirmed_upgrade_decision(self):
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTCONFIRMED")
    upgrade_decision.confirm()
    self.tic()
    redirect_url = self.portal.Base_rejectUpgradeDecision('UD-TESTCONFIRMED')
    self.assertTrue(redirect_url.endswith(
      "?portal_status_message=Thanks%20Upgrade%20Decision%20has%20been"\
      "%20rejected%20Successfully%20%28You%20cannot%20use%20it%20anymore%29."),
      "%s contains the wrong message" %  redirect_url)
    self.assertEquals(upgrade_decision.getSimulationState(), 'rejected')

  def testBase_rejectUpgradeDecision_started_decision(self):
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTSTARTED")
    upgrade_decision.start()
    self.tic()
    redirect_url = self.portal.Base_rejectUpgradeDecision('UD-TESTSTARTED')
    self.assertTrue(redirect_url.endswith(
     "?portal_status_message=Sorry%2C%20This%20Upgrade%20Decision%20is%20"\
     "already%20Started%2C%20you%20cannot%20reject%20it%20anymore."),
     "%s contains the wrong message" %  redirect_url)

  def testBase_rejectUpgradeDecision_stop_decision(self):
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTSTOP")
    upgrade_decision.start()
    upgrade_decision.stop()
    self.tic()
    redirect_url = self.portal.Base_rejectUpgradeDecision('UD-TESTSTOP')
    self.assertTrue(redirect_url.endswith(
      "?portal_status_message=Sorry%2C%20this%20Upgrade%20Decision%20has%20been%20already%20processed."),
      "%s contains the wrong message" %  redirect_url)

  def testBase_rejectUpgradeDecision_delivered_decision(self):
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTDELIVERED")
    upgrade_decision.start()
    upgrade_decision.stop()
    upgrade_decision.deliver()
    self.tic()
    redirect_url = self.portal.Base_rejectUpgradeDecision('UD-TESTDELIVERED')
    self.assertTrue(redirect_url.endswith(
      "?portal_status_message=Sorry%2C%20this%20Upgrade%20Decision%20has%20been%20already%20processed."),
      "%s contains the wrong message" %  redirect_url)

  def testBase_rejectUpgradeDecision_cancelled_decision(self):
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTCANCELLED")
    upgrade_decision.cancel()
    self.tic()
    redirect_url = self.portal.Base_rejectUpgradeDecision('UD-TESTCANCELLED')
    self.assertTrue(redirect_url.endswith(
      "?portal_status_message=Upgrade%20Decision%20is%20already%20Rejected%21"),
      "%s contains the wrong message" %  redirect_url)

  def testBase_rejectUpgradeDecision_reject_decision(self):
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.setReference("UD-TESTREJECT")
    upgrade_decision.reject()
    self.tic()
    redirect_url = self.portal.Base_rejectUpgradeDecision('UD-TESTREJECT')
    self.assertTrue(redirect_url.endswith(
      "?portal_status_message=Upgrade%20Decision%20is%20already%20Rejected%21"),
      "%s contains the wrong message" %  redirect_url)

  @simulate('NotificationTool_getDocumentValue',
            'reference=None',
  'assert reference == "slapos-upgrade-computer.notification"\n' \
  'return context.restrictedTraverse(' \
  'context.REQUEST["testUpgradeDecision_notify_computer"])')
  def testUpgradeDecision_notify_computer(self):
    person = self._makePerson(self.new_id)
    computer = self._makeComputer(self.new_id)
    software_release = self._makeSoftwareRelease(self.new_id)
    software_product = self._makeSoftwareProduct(self.new_id)
    software_release.setAggregateValue(software_product)
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.edit(destination_decision_value=person)
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
    upgrade_decision_line.setAggregateValueList([software_release, computer])
    
    notification_message = self.portal.notification_message_module.newContent(
      portal_type="Notification Message",
      title='Test NM title %s' % self.new_id,
      text_content_substitution_mapping_method_id=
          "NotificationMessage_getSubstitutionMappingDictFromArgument",
      text_content="""${software_product_title}
${computer_title}
${computer_reference}
${software_release_name}
${software_release_reference}
${upgrade_accept_link}
${upgrade_reject_link}
${new_software_release_url}""",
      content_type='text/html',
      )
    self.portal.REQUEST\
        ['testUpgradeDecision_notify_computer'] = \
        notification_message.getRelativeUrl()
    
    self.tic()
    
    self.assertEquals(None, upgrade_decision.UpgradeDecision_notify())
    
    upgrade_decision.plan()
    
    self.tic()
    
    self.assertEquals(None, upgrade_decision.UpgradeDecision_notify())
    
    self.tic()
    
    self.assertEquals(upgrade_decision.getSimulationState(), 'confirmed')
    self.assertEquals(len(upgrade_decision.getFollowUpRelatedValueList()), 1)
    event = upgrade_decision.getFollowUpRelatedValue()
    
    self.assertEquals(event.getTitle(), 
     "New Software available for Installation at %s" % computer.getTitle())
     
    self.assertEqual(event.getTextContent().splitlines(),
      [software_product.getTitle(), computer.getTitle(), computer.getReference(),
       software_release.getTitle(), software_release.getReference(), 
       'Base_acceptUpgradeDecision?reference=%s' % upgrade_decision.getReference(),
       'Base_rejectUpgradeDecision?reference=%s' % upgrade_decision.getReference(),
       software_release.getUrlString()])
      
      
    self.assertEquals(event.getSimulationState(), "delivered")

  @simulate('NotificationTool_getDocumentValue',
            'reference=None',
  'assert reference == "slapos-upgrade-hosting-subscription.notification"\n' \
  'return context.restrictedTraverse(' \
  'context.REQUEST["testUpgradeDecision_notify_hosting_subscription"])')
  def testUpgradeDecision_notify_hosting_subscription(self):
    person = self._makePerson(self.new_id)
    hosting_subscription = self._makeHostingSubscription(self.new_id)
    software_release = self._makeSoftwareRelease(self.new_id)
    software_product = self._makeSoftwareProduct(self.new_id)
    software_release.setAggregateValue(software_product)
    upgrade_decision = self._makeUpgradeDecision()
    upgrade_decision.edit(destination_decision_value=person)
    upgrade_decision_line = self._makeUpgradeDecisionLine(upgrade_decision)
    upgrade_decision_line.setAggregateValueList([software_release, 
                                                hosting_subscription])

    old_url = hosting_subscription.getUrlString()

    notification_message = self.portal.notification_message_module.newContent(
      portal_type="Notification Message",
      title='Test NM title %s' % self.new_id,
      text_content_substitution_mapping_method_id=
          "NotificationMessage_getSubstitutionMappingDictFromArgument",
      text_content="""${software_product_title}
${hosting_subscription_title}
${old_software_release_url}
${software_release_name}
${software_release_reference}
${upgrade_accept_link}
${upgrade_reject_link}
${new_software_release_url}""",
      content_type='text/html',
      )
    self.portal.REQUEST\
        ['testUpgradeDecision_notify_hosting_subscription'] = \
        notification_message.getRelativeUrl()
    
    self.tic()
    
    self.assertEquals(None, upgrade_decision.UpgradeDecision_notify())
    
    upgrade_decision.plan()
    
    self.tic()
    
    self.assertEquals(None, upgrade_decision.UpgradeDecision_notify())
    
    self.tic()
    
    self.assertEquals(upgrade_decision.getSimulationState(), 'confirmed')
    self.assertEquals(len(upgrade_decision.getFollowUpRelatedValueList()), 1)
    event = upgrade_decision.getFollowUpRelatedValue()
    
    self.assertEquals(event.getTitle(), 
     "New Upgrade available for %s" % hosting_subscription.getTitle())
     
    self.assertEqual(event.getTextContent().splitlines(),
      [software_product.getTitle(), hosting_subscription.getTitle(), 
       old_url, software_release.getTitle(), software_release.getReference(), 
       'Base_acceptUpgradeDecision?reference=%s' % upgrade_decision.getReference(),
       'Base_rejectUpgradeDecision?reference=%s' % upgrade_decision.getReference(),
       software_release.getUrlString()])

    self.assertEquals(event.getSimulationState(), "delivered")
1526
    
1527